landing 172512. nsEmbedString for component developers and embeders. r=alec, sr=jag/darin, a=asa@mozilla.org
git-svn-id: svn://10.0.0.236/trunk@132196 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -63,15 +63,11 @@ EXTRA_COMPONENTS = nsSample.js
|
||||
|
||||
# seperate libraries linked in.
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
@@ -47,16 +47,12 @@
|
||||
|
||||
#include "nsSample.h"
|
||||
#include "nsMemory.h"
|
||||
#ifdef XPCOM_GLUE
|
||||
#include "nsXPCOMGlue.h"
|
||||
#endif
|
||||
|
||||
#include "nsEmbedString.h"
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsSampleImpl::nsSampleImpl() : mValue(nsnull)
|
||||
{
|
||||
#ifdef XPCOM_GLUE
|
||||
XPCOMGlueStartup("XPCOMComponentGlue");
|
||||
#endif
|
||||
NS_INIT_ISUPPORTS();
|
||||
mValue = (char*)nsMemory::Clone("initial value", 14);
|
||||
}
|
||||
@@ -65,10 +61,6 @@ nsSampleImpl::~nsSampleImpl()
|
||||
{
|
||||
if (mValue)
|
||||
nsMemory::Free(mValue);
|
||||
|
||||
#ifdef XPCOM_GLUE
|
||||
XPCOMGlueShutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,6 +142,12 @@ nsSampleImpl::Poke(const char* aValue)
|
||||
return SetValue((char*) aValue);
|
||||
}
|
||||
|
||||
|
||||
static void GetStringValue(nsACString& aValue)
|
||||
{
|
||||
aValue.Assign("GetValue");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSampleImpl::WriteValue(const char* aPrefix)
|
||||
{
|
||||
@@ -158,5 +156,27 @@ nsSampleImpl::WriteValue(const char* aPrefix)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
printf("%s %s\n", aPrefix, mValue);
|
||||
|
||||
// This next part illustrates the nsEmbedString:
|
||||
nsEmbedString foopy;
|
||||
foopy.Append(PRUnichar('f'));
|
||||
foopy.Append(PRUnichar('o'));
|
||||
foopy.Append(PRUnichar('o'));
|
||||
foopy.Append(PRUnichar('p'));
|
||||
foopy.Append(PRUnichar('y'));
|
||||
|
||||
const PRUnichar* f = foopy.get();
|
||||
PRUint32 l = foopy.Length();
|
||||
printf("%c%c%c%c%c %d\n", char(f[0]), char(f[1]), char(f[2]), char(f[3]), char(f[4]), l);
|
||||
|
||||
nsEmbedCString foopy2;
|
||||
GetStringValue(foopy2);
|
||||
|
||||
//foopy2.Append(NS_LITERAL_CSTRING("foopy"));
|
||||
const char* f2 = foopy2.get();
|
||||
PRUint32 l2 = foopy2.Length();
|
||||
|
||||
printf("%s %d\n", f2, l2);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
#ifdef XPCOM_GLUE
|
||||
#include "nsXPCOMGlue.h"
|
||||
#include "nsMemory.h"
|
||||
#endif
|
||||
|
||||
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
|
||||
@@ -114,8 +115,14 @@ main(void)
|
||||
return -3;
|
||||
}
|
||||
printf("Set value to: %s\n", testValue);
|
||||
#ifndef XPCOM_GLUE
|
||||
nsXPIDLCString str;
|
||||
rv = mysample->GetValue(getter_Copies(str));
|
||||
#else
|
||||
char *str;
|
||||
rv = mysample->GetValue(&str);
|
||||
#endif
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: Calling nsISample::GetValue() [%x]\n", rv);
|
||||
@@ -127,6 +134,9 @@ main(void)
|
||||
return -4;
|
||||
}
|
||||
|
||||
#ifdef XPCOM_GLUE
|
||||
nsMemory::Free(str);
|
||||
#endif
|
||||
rv = mysample->WriteValue("Final print :");
|
||||
printf("Test passed.\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user