1 /*---------------------------------------------------------------------------*
2 Project: Revolution ENC sample demo
3 File: validate.c
4
5 Copyright 2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: validate.c,v $
14 Revision 1.2 2006/11/14 08:34:26 yoshioka_yasuhiro
15 Modified the buffer.
16
17 Revision 1.1 2006/10/27 12:20:37 yoshioka_yasuhiro
18 Initial commit.
19
20 $NoKeywords: $
21 *---------------------------------------------------------------------------*/
22
23 #include <revolution.h>
24 #include <revolution/enc.h>
25
26 #include "validate.h"
27
ValidateFuncToUnicode(ConvertToUnicode func,const u16 * wcs,const u8 * mbs,s32 count)28 BOOL ValidateFuncToUnicode(ConvertToUnicode func, const u16 *wcs, const u8 *mbs, s32 count)
29 {
30 s32 dstlen;
31 s32 srclen = -1;
32 ENCResult result = (*func)(NULL, &dstlen, mbs, &srclen);
33 if (result != ENC_OK)
34 {
35 OSReport("ERROR: %d\n", result);
36 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
37 return FALSE;
38 }
39 else
40 {
41 u16 dst[LENGTH];
42 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
43 result = (*func)(dst, &dstlen, mbs, &srclen);
44 if (result != ENC_OK)
45 {
46 OSReport("ERROR: %d\n", result);
47 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
48 return FALSE;
49 }
50 else
51 {
52 s32 i, j;
53 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
54 for (i = 0; i < dstlen; ++i)
55 {
56 if (dst[i] == wcs[i])
57 continue;
58 OSReport("FAILURE\nend @ %d\n", i);
59 OSReport("result\tanswer\n");
60 for (j = 0; j < count; ++j)
61 OSReport("%#x\t%#x\n", dst[i + j], wcs[i + j]);
62 return FALSE;
63 }
64 OSReport("SUCCESS\nend @ %d\n", i - 1);
65 return TRUE;
66 }
67 }
68 }
69
ValidateFuncFromUnicode(ConvertFromUnicode func,const u8 * mbs,const u16 * wcs,s32 count)70 BOOL ValidateFuncFromUnicode(ConvertFromUnicode func, const u8 *mbs, const u16 *wcs, s32 count)
71 {
72 s32 dstlen;
73 s32 srclen = -1;
74 ENCResult result = (*func)(NULL, &dstlen, wcs, &srclen);
75 if (result != ENC_OK)
76 {
77 OSReport("ERROR: %d\n", result);
78 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
79 return FALSE;
80 }
81 else
82 {
83 u8 dst[LENGTH];
84 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
85 result = (*func)(dst, &dstlen, wcs, &srclen);
86 if (result != ENC_OK)
87 {
88 OSReport("ERROR: %d\n", result);
89 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
90 return FALSE;
91 }
92 else
93 {
94 s32 i, j;
95 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
96 for (i = 0; i < dstlen; ++i)
97 {
98 if (dst[i] == mbs[i])
99 continue;
100 OSReport("FAILURE\nend @ %d\n", i);
101 OSReport("result\tanswer\n");
102 for (j = 0; j < count; ++j)
103 OSReport("%#x\t%#x\n", dst[i + j], mbs[i + j]);
104 return FALSE;
105 }
106 OSReport("SUCCESS\nend @ %d\n", i - 1);
107 return TRUE;
108 }
109 }
110 }
111
ValidateFuncMultiByte(ConvertMultiByte func,const u8 * dstmbs,const u8 * srcmbs,s32 count)112 BOOL ValidateFuncMultiByte(ConvertMultiByte func, const u8 *dstmbs, const u8 *srcmbs, s32 count)
113 {
114 s32 dstlen;
115 s32 srclen = -1;
116 ENCResult result = (*func)(NULL, &dstlen, srcmbs, &srclen);
117 if (result != ENC_OK)
118 {
119 OSReport("ERROR: %d\n", result);
120 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
121 return FALSE;
122 }
123 else
124 {
125 u8 dst[LENGTH];
126 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
127 result = (*func)(dst, &dstlen, srcmbs, &srclen);
128 if (result != ENC_OK)
129 {
130 OSReport("ERROR: %d\n", result);
131 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
132 return FALSE;
133 }
134 else
135 {
136 s32 i, j;
137 OSReport("dstlen: %d, srclen: %d\n", dstlen, srclen);
138 for (i = 0; i < dstlen; ++i)
139 {
140 if (dst[i] == dstmbs[i])
141 continue;
142 OSReport("FAILURE\nend @ %d\n", i);
143 OSReport("result\tanswer\n");
144 for (j = 0; j < count; ++j)
145 OSReport("%#x\t%#x\n", dst[i + j], dstmbs[i + j]);
146 return FALSE;
147 }
148 OSReport("SUCCESS\nend @ %d\n", i - 1);
149 return TRUE;
150 }
151 }
152 }