summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/trtl.c
blob: 930b695d4da951268c7d5aecf2022a003a8e5215 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    trtl.c

Abstract:

    Test program for the NT OS Runtime Library (RTL)

Author:

    Steve Wood (stevewo) 31-Mar-1989

Revision History:

--*/

#include <os2.h>
#include <stdio.h>
#include <process.h>
#include "nt.h"
#include "ntrtl.h"

char *TestMemoryStrings[] = {
    "",
    "1",
    "12",
    "123",
    "1234",
    "12345",
    "123456",
    "1234567",
    "12345678",
    "123456789",
    "123456789A",
    NULL
};


BOOLEAN
StringCompare(
    IN PSTRING String1,
    IN PSTRING String2,
    IN BOOLEAN CaseInSensitive,
    IN LONG ExpectedResult
    )
{
    LONG Result = RtlCompareString( String1, String2, CaseInSensitive );

    if (Result < 0) {
        Result = -1L;
        }
    else {
        if (Result > 0) {
            Result = 1L;
            }
        }

    if (Result != ExpectedResult) {
        DbgPrint( "RtlCompareString( \"%.*s\", \"%.*s\", %d ) == %ld (%ld)\n",
                String1->Length, String1->Buffer,
                String2->Length, String2->Buffer,
                CaseInSensitive,
                Result, ExpectedResult
                );
        return( FALSE );
        }
    else {
        return( TRUE );
        }
}

BOOLEAN
StringEqual(
    IN PSTRING String1,
    IN PSTRING String2,
    IN BOOLEAN CaseInSensitive,
    IN BOOLEAN ExpectedResult
    )
{
    BOOLEAN Result = RtlEqualString( String1, String2, CaseInSensitive );

    if (Result != ExpectedResult) {
        DbgPrint( "RtlEqualString( \"%.*s\", \"%.*s\", %d ) == %d (%d)\n",
                String1->Length, String1->Buffer,
                String2->Length, String2->Buffer,
                CaseInSensitive,
                Result, ExpectedResult );
        return( FALSE );
        }
    else {
        return( TRUE );
        }
}

VOID
DumpString(
    IN PCH StringTitle,
    IN PSTRING String
    )
{
    DbgPrint( "%s: (%d, %d) \"%.*s\"\n", StringTitle,
                                       String->MaximumLength,
                                       String->Length,
                                       String->Length,
                                       String->Buffer );
}


BOOLEAN
TestString( void )
{
    BOOLEAN Result;
    char buffer5[ 80 ], buffer6[ 15 ], buffer7[ 3 ];
    STRING String1, String2, String3, String4;
    STRING String5, String6, String7, String8;
                            //         1         2
                            //12345678901234567890
                            //
    RtlInitString( &String1, " One" );
    RtlInitString( &String2, " Two" );
    RtlInitString( &String3, " Three" );
    RtlInitString( &String4, " Four" );
    String5.Buffer = buffer5;
    String5.MaximumLength = sizeof( buffer5 );
    String5.Length = 0;
    String6.Buffer = buffer6;
    String6.MaximumLength = sizeof( buffer6 );
    String6.Length = 0;
    String7.Buffer = buffer7;
    String7.MaximumLength = sizeof( buffer7 );
    String7.Length = 0;
    String8.Buffer = NULL;
    String8.MaximumLength = 0;
    String8.Length = 0;
    RtlCopyString( &String5, &String1 );
    RtlCopyString( &String6, &String2 );
    RtlCopyString( &String7, &String3 );
    RtlCopyString( &String8, &String4 );

    DumpString( "String1", &String1 );
    DumpString( "String2", &String2 );
    DumpString( "String3", &String3 );
    DumpString( "String4", &String4 );
    DumpString( "String5", &String5 );
    DumpString( "String6", &String6 );
    DumpString( "String7", &String7 );
    DumpString( "String8", &String8 );

    Result = TRUE;
    Result &= StringCompare( &String1, &String1, FALSE, 0L );
    Result &= StringCompare( &String1, &String2, FALSE, -1L);
    Result &= StringCompare( &String1, &String3, FALSE, -1L);
    Result &= StringCompare( &String1, &String4, FALSE, 1L );
    Result &= StringCompare( &String1, &String5, FALSE, 0L );
    Result &= StringCompare( &String1, &String6, FALSE, -1L);
    Result &= StringCompare( &String1, &String7, FALSE, -1L);
    Result &= StringCompare( &String1, &String8, FALSE, 1L );

    Result &= StringEqual( &String1, &String1, FALSE, 1 );
    Result &= StringEqual( &String1, &String2, FALSE, 0 );
    Result &= StringEqual( &String1, &String3, FALSE, 0 );
    Result &= StringEqual( &String1, &String4, FALSE, 0 );
    Result &= StringEqual( &String1, &String5, FALSE, 1 );
    Result &= StringEqual( &String1, &String6, FALSE, 0 );
    Result &= StringEqual( &String1, &String7, FALSE, 0 );
    Result &= StringEqual( &String1, &String8, FALSE, 0 );

    return( Result );
}


int
_CDECL
main(
    int argc,
    char *argv[]
    )
{
    if (!TestString()) {
        DbgPrint( "TRTL: TestString failed\n" );
        exit( 1 );
        }

    exit( 0 );
    return( 0 );
}