change dependency. add sjis test cases

This commit is contained in:
ftang%netscape.com 1999-01-12 08:35:45 +00:00
parent 1aba6b47b6
commit e05c75c1c9
3 changed files with 196 additions and 2 deletions

View File

@ -17,6 +17,8 @@
DEPTH=..\..
DIRS=public src tests
DIRS=public src \
ucvja \
tests
include <$(DEPTH)\layout\config\rules.mak>

View File

@ -39,7 +39,8 @@ OBJS = \
LINCS= \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\intl \
-I$(PUBLIC)\uconv \
-I$(PUBLIC)\ucvja \
$(NULL)
LLIBS= \

View File

@ -25,6 +25,23 @@
#include "nsICharsetConverterManager.h"
#include "nsConverterCID.h"
#define TEST_SJIS
#ifdef TEST_SJIS
#include "nsUCVJACID.h"
#ifdef XP_UNIX
#define UCVJA_DLL "libucvja.so"
#else
#ifdef XP_MAC
#define UCVJA_DLL "UCVJA_DLL"
#else /* XP_MAC */
#define UCVJA_DLL "ucvja.dll"
#endif
#endif
#endif
#ifdef XP_UNIX
#define UCONV_DLL "libuconv.so"
#else
@ -36,6 +53,7 @@
#endif
#define TABLE_SIZE1 5
nsICharsetConverterManager * ccMan = NULL;
nsresult setupRegistry()
@ -46,6 +64,13 @@ nsresult setupRegistry()
if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
res = nsRepository::RegisterFactory(kAscii2UnicodeCID, UCONV_DLL, PR_FALSE, PR_FALSE);
#ifdef TEST_SJIS
if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
res = nsRepository::RegisterFactory(kSJIS2UnicodeCID, UCVJA_DLL, PR_FALSE, PR_FALSE);
#endif
return res;
}
@ -162,7 +187,167 @@ nsresult testAsciiDecoder()
return NS_OK;
}
#ifdef TEST_SJIS
#define SJIS_TEST_SRC_SIZE 40
#define SJIS_TEST_DEST_SIZE 24
nsresult testSJISDecoder()
{
/*
[Shift_JIS=4a][Shift_JIS=61][Shift_JIS=70][Shift_JIS=61][Shift_JIS=6e][Shift_JIS=65][Shift_JIS=73][Shift_JIS=65]
[Shift_JIS=8abf][Shift_JIS=8e9a]
[Shift_JIS=834a][Shift_JIS=835e][Shift_JIS=834a][Shift_JIS=8369]
[Shift_JIS=82d0][Shift_JIS=82e7][Shift_JIS=82aa][Shift_JIS=82c8]
[Shift_JIS=8250][Shift_JIS=8251][Shift_JIS=8252][Shift_JIS=8260][Shift_JIS=8261][Shift_JIS=8262]
U+004A U+0061 U+0070 U+0061 U+006E U+0065 U+0073 U+0065
U+6F22 U+5B57
U+30AB U+30BF U+30AB U+30CA
U+3072 U+3089 U+304C U+306A
U+FF11 U+FF12 U+FF13 U+FF21 U+FF22 U+FF23
*/
static const char src[SJIS_TEST_SRC_SIZE + 1] = {
"Japanese" /* English */
"\x8a\xbf\x8e\x9a" /* Kanji */
"\x83\x4a\x83\x5e\x83\x4a\x83\x69" /* Kantakana */
"\x82\xd0\x82\xe7\x82\xaa\x82\xc8" /* Hiragana */
"\x82\x50\x82\x51\x82\x52\x82\x60\x82\x61\x82\x62" /* full width 123ABC */
};
static const PRUnichar expect[SJIS_TEST_DEST_SIZE] = {
0x004A, 0x0061, 0x0070, 0x0061, 0x006E, 0x0065, 0x0073, 0x0065,
0x6f22, 0x5b57,
0x30ab, 0x30bf, 0x30ab, 0x30ca,
0x3072, 0x3089, 0x304c, 0x306a,
0xff11, 0xff12, 0xff13, 0xff21, 0xff22, 0xff23
};
PRUnichar dest[SJIS_TEST_DEST_SIZE + 44];
printf("\n[T3] SJIS2Unicode\n");
// create converter
nsIUnicodeDecoder * dec;
nsAutoString str("Shift_JIS");
nsresult res = ccMan->GetUnicodeDecoder(&str,&dec);
if (NS_FAILED(res)) {
printf("ERROR 0x%x: Cannot instantiate.\n",res);
return res;
} else {
printf("Instantiated.\n");
}
//test converter
PRInt32 srcL = SJIS_TEST_SRC_SIZE;
PRInt32 destL = SJIS_TEST_DEST_SIZE+ 44;
PRBool failed = PR_FALSE;
printf("Test Normal Case\n");
res=dec->Convert(dest, 0, &destL, src, 0, &srcL);
if (NS_FAILED(res)) {
printf("ERROR 0x%x: Convert().\n",res);
failed = PR_TRUE;
} else {
printf("Read %d, write %d.\n",srcL,destL);
printf("Converted:");
if(destL != SJIS_TEST_DEST_SIZE)
{
printf("Dest Size bad. Should be %d but got %d!!\n",
SJIS_TEST_DEST_SIZE, destL);
failed = PR_TRUE;
}
for (int i=0;i< destL ;i++) {
if (dest[i] != expect[i] ) failed = PR_TRUE;
}
printf("\n");
if (failed) {
printf("Test FAILED!!!\n");
} else {
printf("Test Passed.\n");
}
failed = PR_FALSE;
// Test NS_PARTIAL_MORE_INPUT case
printf("Test NS_PARTIAL_MORE_INPUT Case\n");
srcL= SJIS_TEST_SRC_SIZE - 1;
destL = SJIS_TEST_DEST_SIZE+ 44;
res=dec->Convert(dest, 0, &destL, src, 0, &srcL);
if (NS_PARTIAL_MORE_INPUT != res) {
printf("ERROR 0x%x: Convert().\n",res);
failed = PR_TRUE;
} else {
if((SJIS_TEST_SRC_SIZE -2 ) != srcL )
{
printf("Src Size bad. Should be %d but got %d!!\n",
SJIS_TEST_SRC_SIZE-2, srcL);
failed = PR_TRUE;
}
if(destL != (SJIS_TEST_DEST_SIZE-1))
{
printf("Dest Size bad. Should be %d but got %d!!\n",
SJIS_TEST_DEST_SIZE-1, destL);
failed = PR_TRUE;
}
for (int i=0;i< destL ;i++) {
if (dest[i] != expect[i] ) failed = PR_TRUE;
}
}
if (failed) {
printf("Test FAILED!!!\n");
} else {
printf("Test Passed.\n");
}
failed = PR_FALSE;
// Test NS_PARTIAL_MORE_OUTPUT case
printf("Test NS_PARTIAL_MORE_OUTNPUT Case\n");
srcL= SJIS_TEST_SRC_SIZE;
destL = SJIS_TEST_DEST_SIZE-1;
res=dec->Convert(dest, 0, &destL, src, 0, &srcL);
if (NS_PARTIAL_MORE_OUTPUT != res) {
printf("ERROR 0x%x: Convert().\n",res);
failed = PR_TRUE;
} else {
if((SJIS_TEST_SRC_SIZE -2 ) != srcL )
{
printf("Src Size bad. Should be %d but got %d!!\n",
SJIS_TEST_SRC_SIZE-2, srcL);
failed = PR_TRUE;
}
if(destL != (SJIS_TEST_DEST_SIZE-1))
{
printf("Dest Size bad. Should be %d but got %d!!\n",
SJIS_TEST_DEST_SIZE-1, destL);
failed = PR_TRUE;
}
for (int i=0;i< destL ;i++) {
if (dest[i] != expect[i] ) failed = PR_TRUE;
}
}
// Test NS_ERROR_ILLEGAL_INPUT case
//printf("Test NS_ERROR_ILLEGAL_INPUT Case\n");
// To Be Implement
if (failed) {
printf("Test FAILED!!!\n");
} else {
printf("Test Passed.\n");
}
}
NS_RELEASE(dec);
return NS_OK;
}
#endif
nsresult run()
{
nsresult res;
@ -172,6 +357,12 @@ nsresult run()
res = testAsciiDecoder();
#ifdef TEST_SJIS
if (NS_FAILED(res)) return res;
res = testSJISDecoder();
#endif
return NS_OK;
}