adding a string getter tests as an example for bug 9227

git-svn-id: svn://10.0.0.236/trunk@38204 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jband%netscape.com
1999-07-03 00:34:35 +00:00
parent efc2193fda
commit 281c645be7
6 changed files with 130 additions and 0 deletions

View File

@@ -103,3 +103,9 @@ interface nsIXPCTestOther : nsISupports {
interface nsIXPCTestNoisy : nsISupports {
void squawk();
};
[scriptable, uuid(d970e910-30d8-11d3-9885-006008962422)]
interface nsIXPCTestString : nsISupports {
string GetStringA();
void GetStringB(out string s);
};

View File

@@ -34,6 +34,7 @@ CPPSRCS= \
xpctest_echo.cpp \
xpctest_child.cpp \
xpctest_noisy.cpp \
xpctest_string.cpp \
xpctest_module.cpp \
$(NULL)

View File

@@ -30,6 +30,7 @@ OBJS= \
.\$(OBJDIR)\xpctest_echo.obj \
.\$(OBJDIR)\xpctest_child.obj \
.\$(OBJDIR)\xpctest_noisy.obj \
.\$(OBJDIR)\xpctest_string.obj \
.\$(OBJDIR)\xpctest_module.obj \
$(NULL)

View File

@@ -51,6 +51,8 @@ NSGetFactory(nsISupports* aServMgr,
rv = factory->SetConstructor(xpctest::ConstructChild);
else if(aClass.Equals(xpctest::GetNoisyCID()))
rv = factory->SetConstructor(xpctest::ConstructNoisy);
else if(aClass.Equals(xpctest::GetStringTestCID()))
rv = factory->SetConstructor(xpctest::ConstructStringTest);
else
{
NS_ASSERTION(0, "incorrectly registered");
@@ -89,6 +91,10 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
"nsNoisy", "nsNoisy", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetStringTestCID(),
"nsStringTest", "nsStringTest", aPath,
PR_TRUE, PR_TRUE);
return rv;
}
@@ -103,6 +109,7 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
rv = compMgr->UnregisterComponent(xpctest::GetEchoCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetChildCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetNoisyCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetStringTestCID(), aPath);
return rv;
}

View File

@@ -49,6 +49,10 @@
{ 0xfd774840, 0x237b, 0x11d3, \
{ 0x98, 0x79, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
// {4DD7EC80-30D9-11d3-9885-006008962422}
#define NS_STRING_TEST_CID \
{ 0x4dd7ec80, 0x30d9, 0x11d3,\
{ 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
// 'namespace' class
class xpctest
@@ -63,6 +67,9 @@ public:
static const nsID& GetNoisyCID() {static nsID cid = NS_NOISY_CID; return cid;}
static NS_METHOD ConstructNoisy(nsISupports *aOuter, REFNSIID aIID, void **aResult);
static const nsID& GetStringTestCID() {static nsID cid = NS_STRING_TEST_CID; return cid;}
static NS_METHOD ConstructStringTest(nsISupports *aOuter, REFNSIID aIID, void **aResult);
private:
xpctest(); // not implemented
};

View File

@@ -0,0 +1,108 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* implement nsIXPCTestString for testing. */
#include "xpctest_private.h"
class xpcstringtest : public nsIXPCTestString
{
public:
NS_DECL_ISUPPORTS
/* string GetStringA (); */
NS_IMETHOD GetStringA(char **_retval);
/* void GetStringB (out string s); */
NS_IMETHOD GetStringB(char **s);
xpcstringtest();
virtual ~xpcstringtest();
};
xpcstringtest::xpcstringtest()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
xpcstringtest::~xpcstringtest()
{
}
static NS_DEFINE_IID(kxpcstringtestIID, NS_IXPCTESTSTRING_IID);
NS_IMPL_ISUPPORTS(xpcstringtest, kxpcstringtestIID);
/* string GetStringA (); */
NS_IMETHODIMP
xpcstringtest::GetStringA(char **_retval)
{
const char myResult[] = "result of xpcstringtest::GetStringA";
if(!_retval)
return NS_ERROR_NULL_POINTER;
*_retval = (char*) nsAllocator::Clone(myResult,
sizeof(char)*(strlen(myResult)+1));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/* void GetStringB (out string s); */
NS_IMETHODIMP
xpcstringtest::GetStringB(char **s)
{
const char myResult[] = "result of xpcstringtest::GetStringB";
if(!s)
return NS_ERROR_NULL_POINTER;
*s = (char*) nsAllocator::Clone(myResult,
sizeof(char)*(strlen(myResult)+1));
return *s ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/***************************************************************************/
// static
NS_IMETHODIMP
xpctest::ConstructStringTest(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
NS_ASSERTION(aOuter == nsnull, "no aggregation");
xpcstringtest* obj = new xpcstringtest();
if(obj)
{
rv = obj->QueryInterface(aIID, aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
NS_RELEASE(obj);
}
else
{
*aResult = nsnull;
rv = NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
/***************************************************************************/