#include "moz.h"

class nsISupports {
public:
  virtual nsresult QueryInterface(REFNSIID aIID, void** aInstancePtr) = 0;
};

class nsFoo : nsISupports {
  void test(REFNSIID aIID, nsISupports** aSupports) {
    nsFoo* f = this;
    if (NS_FAILED(f->QueryInterface(aIID, (void **)aSupports))) {
    }
    else if (NS_SUCCEEDED(f->QueryInterface(aIID, reinterpret_cast<void**>(&member)))) {
    }
  }
public:
  nsresult QueryInterface(REFNSIID, void**);
  nsISupports *member;
};

class nsMacroTester : public nsFoo {
  NS_IMETHOD QueryInterface(REFNSIID, void**);
};

nsresult bla(void **foo);

NS_IMETHODIMP nsMacroTester::QueryInterface(REFNSIID id, void** foo ) {
  nsresult rv;
  rv = nsFoo::QueryInterface(id, foo);
  if (rv != NS_OK)
    return NS_ERROR_NULL_POINTER;
  /* need to add a case for
    nsCOMPtr<Bah> foo;
    nsFoo::QueryInterface(id, (void**)getter_AddRefs(foo))
   */
  return bla(foo);
}

nsresult nsFoo::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
  NS_ENSURE_ARG_POINTER(aInstancePtr);
  return nsISupports::QueryInterface(aIID, aInstancePtr);
}

class nsMultipleStatementsOnLine : public nsISupports {
  nsresult QueryInterface(REFNSIID aIID, void** aInstancePtr);

};
nsresult nsMultipleStatementsOnLine::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
  NS_ENSURE_ARG_POINTER(aInstancePtr); return nsISupports::QueryInterface(aIID, aInstancePtr);
}
