add a test with an 'out' array of strings

This commit is contained in:
jband%netscape.com 2000-04-15 18:44:22 +00:00
Родитель 5d701a4a28
Коммит d946b71592
3 изменённых файлов: 55 добавлений и 0 удалений

Просмотреть файл

@ -322,6 +322,32 @@ xpcarraytest::DoubleString(PRUint32 *count, char **str)
return NS_OK;
}
/* void GetStrings (out PRUint32 count, [array, size_is (count), retval] out string str); */
NS_IMETHODIMP
xpcarraytest::GetStrings(PRUint32 *count, char ***str)
{
const static char *strings[] = {"one", "two", "three", "four"};
const static scount = sizeof(strings)/sizeof(strings[0]);
if(mReceiver)
return mReceiver->GetStrings(count, str);
char** out = (char**) nsAllocator::Alloc(scount * sizeof(char*));
if(!out)
return NS_ERROR_OUT_OF_MEMORY;
for(int i = 0; i < scount; ++i)
{
out[i] = (char*) nsAllocator::Clone(strings[i], strlen(strings[i])+1);
// failure unlikely, leakage foolishly tolerated in this test case
if(!out[i])
return NS_ERROR_OUT_OF_MEMORY;
}
*count = scount;
*str = out;
return NS_OK;
}
/***************************************************************************/
// static

Просмотреть файл

@ -209,5 +209,9 @@ interface nsIXPCTestArray : nsISupports {
[size_is(count)] in string str);
void DoubleString(inout PRUint32 count,
[size_is(count)] inout string str);
void GetStrings(out PRUint32 count,
[retval, array, size_is(count)] out string str);
};

Просмотреть файл

@ -281,3 +281,28 @@ print("\""+str2.value+"\""+" ; "+len2.value);
obj.DoubleString(len2, str2);
print("\""+str2.value+"\""+" ; "+len2.value);
print("-------------------------------------------");
print("GetStrings test...");
obj.SetReceiver(null);
var count = {};
var strings = obj.GetStrings(count);
print("count = "+ count.value);
print("strings = "+ strings);
print("-----------------------");
var gs = {
GetStrings : function(count) {
var s = ['red', 'green', 'blue'];
count.value = s.length;
return s;
}
};
obj.SetReceiver(gs);
var count = {};
var strings = obj.GetStrings(count);
print("count = "+ count.value);
print("strings = "+ strings);
print("\n");