1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPLv2+ - See COPYING in the top level directory
4  * PURPOSE:         Tests for IsDBCSLeadByteEx
5  * PROGRAMMER:      Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
10 #define MAX_RANGE   4
11 
12 typedef struct RANGE
13 {
14     int StartIndex;
15     int EndIndex;
16 } RANGE;
17 
18 typedef struct ENTRY
19 {
20     const char *Name;
21     int CodePage;
22     int RangeCount;
23     RANGE Ranges[MAX_RANGE];
24 } ENTRY;
25 
26 START_TEST(IsDBCSLeadByteEx)
27 {
28     static const ENTRY Entries[] =
29     {
30         {
31             "English", 437,
32             0
33         },
34         {
35             "ChineseSimpilified", 936,
36             1,
37             {
38                 { 0x81, 0xFE }
39             }
40         },
41         {
42             "ChineseTraditional", 950,
43             1,
44             {
45                 { 0x81, 0xFE }
46             }
47         },
48         {
49             "Japanese", 932,
50             2,
51             {
52                 { 0x81, 0x9F }, { 0xE0, 0xFC }
53             }
54         },
55         {
56             "Korean", 949,
57             1,
58             {
59                 { 0x81, 0xFE }
60             }
61         }
62     };
63     int i;
64 
65     for (i = 0; i < _countof(Entries); ++i)
66     {
67         int Index, iRange;
68         int CodePage = Entries[i].CodePage, StartIndex = 0, RangeCount = 0;
69         BOOL InRange = FALSE;
70         RANGE Ranges[MAX_RANGE];
71         const char *Name = Entries[i].Name;
72 
73         ZeroMemory(&Ranges, sizeof(Ranges));
74 
75         for (Index = 0; Index < 256; ++Index)
76         {
77             if (InRange)
78             {
79                 if (!IsDBCSLeadByteEx(CodePage, Index))
80                 {
81                     Ranges[RangeCount].StartIndex = StartIndex;
82                     Ranges[RangeCount].EndIndex = Index - 1;
83                     ++RangeCount;
84                     InRange = FALSE;
85                 }
86             }
87             else
88             {
89                 if (IsDBCSLeadByteEx(CodePage, Index))
90                 {
91                     StartIndex = Index;
92                     InRange = TRUE;
93                 }
94             }
95         }
96         if (InRange)
97         {
98             Ranges[RangeCount].StartIndex = StartIndex;
99             Ranges[RangeCount].EndIndex = Index - 1;
100             ++RangeCount;
101         }
102 
103         ok(RangeCount == Entries[i].RangeCount,
104            "%s: RangeCount expected %d, was %d\n",
105            Name, Entries[i].RangeCount, RangeCount);
106         for (iRange = 0; iRange < Entries[i].RangeCount; ++iRange)
107         {
108             const RANGE *pRange = &Entries[i].Ranges[iRange];
109             int iStart = Ranges[iRange].StartIndex;
110             int iEnd = Ranges[iRange].EndIndex;
111             ok(iStart == pRange->StartIndex,
112                "%s: Ranges[%d].StartIndex expected: 0x%02X, was: 0x%02X\n",
113                Name, iRange, pRange->StartIndex, iStart);
114             ok(iEnd == pRange->EndIndex,
115                "%s: Ranges[%d].EndIndex was expected: 0x%02X, was: 0x%02X\n",
116                Name, iRange, pRange->EndIndex, iEnd);
117         }
118     }
119 }
120