summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/tnlsxlat.c
blob: 045557538b412315e7afefdbbd5569148a229d3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    tnlsxlat.c

Abstract:

    Test program for the Nlsxlat Procedures

Author:

    Ian James     [IanJa]    03-Feb-1994

Revision History:

--*/

#include <stdio.h>

#include "nt.h"
#include "ntrtl.h"

#define NELEM(p) (sizeof(p) / sizeof(*(p)))

char OEMBuff[1000];
char ABuff[1000];
WCHAR UBuff[2000];

int
main(
    int argc,
    char *argv[]
    )
{
    ULONG j;
    ULONG cb;
    char *pch;

    printf("Start NlsXlatTest()\n");

    //
    //  First initialize the buffers
    //

    for (j = 0; j < sizeof(OEMBuff); j++) {
        OEMBuff[j] = (char)(j * 17);
        ABuff[j] = (char)(j * 19);
    }

    //
    //  TEST 1
    //  RtlMultiByteToUnicodeN, RtlUnicodeToMultiByteN
    //

    printf("Test 1: MultiByteToUnicodeN & RtlUnicodeToMultiByteN\n");

    // TEST 1.1
    //
    printf("  Test 1.1: A->U U->A\n");

    RtlMultiByteToUnicodeN(UBuff, sizeof(UBuff), &cb, ABuff, sizeof(ABuff));
    printf("    %d bytes converted to Unicode\n", cb);
    RtlUnicodeToMultiByteN(ABuff, sizeof(ABuff), &cb, UBuff, sizeof(UBuff));
    printf("    %d bytes converted back to ANSI\n", cb);

    for (j = 0; j < sizeof(ABuff); j++) {
        if (ABuff[j] != (char)(j * 19)) {
            printf("ABuff[%d] was 0x%02x, now 0x%02x\n",
                    j, (char)(j * 19), ABuff[j]);
            return FALSE;
        }
    }
    printf("    Test 1.1 OK\n");

    // TEST 1.2
    //
    printf("  Test 1.2: A->U U->A (source & dest buffers the same)\n");
    RtlCopyMemory(UBuff, ABuff, sizeof(ABuff));
    
    RtlMultiByteToUnicodeN(UBuff, sizeof(UBuff), &cb, UBuff, sizeof(ABuff));
    printf("    %d bytes converted to Unicode\n", cb);
    RtlUnicodeToMultiByteN(UBuff, sizeof(ABuff), &cb, UBuff, sizeof(UBuff));
    printf("    %d bytes converted back to ANSI\n", cb);

    pch = (LPSTR)UBuff;
    for (j = 0; j < sizeof(ABuff); j++) {
        if (pch[j] != ABuff[j]) {
            printf("    ABuff[%d] was 0x%02x, was turned into 0x%02x\n",
                    j, ABuff[j], pch[j]);
            printf("    Test 1.2 FAILED!\n");
            return FALSE;
        }
    }

    printf("    Test 1.2 OK!\n");

    return TRUE;
}