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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/* Copyright (C) 2023, SWITCH */
/* See LICENSE for licensing information. */
#include "../util.h"
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int testcount = 0;
{
char *str = "test";
if (verifyutf8((uint8_t *)str, strlen(str)) != 1)
printf("not ");
printf("ok %d - simple test ascii\n", ++testcount);
}
{
char *str = "smile 😀";
if (verifyutf8((uint8_t *)str, strlen(str)) != 1)
printf("not ");
printf("ok %d - original utf8 string\n", ++testcount);
}
{
uint8_t str[] = {0x00, 'x', 0x00};
if (verifyutf8(str, 2) != 0)
printf("not ");
printf("ok %d - simple test null char\n", ++testcount);
}
{
uint8_t str[] = {0x01, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - control characters first\n", ++testcount);
}
{
uint8_t str[] = {0x1F, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - control characters last\n", ++testcount);
}
{
uint8_t str[] = {0x7F, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - delete\n", ++testcount);
}
{
uint8_t str[] = {'t', 0x00, 's', 't', 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - invalid 2nd char\n", ++testcount);
}
{
uint8_t str[] = {'t', 'e', 0x00, 't', 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - invalid 3rd char\n", ++testcount);
}
{
uint8_t str[] = {'t', 'e', 's', 0x00, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - invalid 4th char\n", ++testcount);
}
{
uint8_t str[] = {0x80, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - invalid continuation single byte\n", ++testcount);
}
{
uint8_t str[] = {0xFF, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - invalid byte\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0xA0, 0x00};
if (verifyutf8(str, 2) != 1)
printf("not ");
printf("ok %d - 2-byte char first codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xDF, 0xBF, 0x00};
if (verifyutf8(str, 2) != 1)
printf("not ");
printf("ok %d - 2-byte char last codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xC0, 0x80, 0x00};
if (verifyutf8(str, 2) != 0)
printf("not ");
printf("ok %d - overlong 1-byte\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0x80, 0x00};
if (verifyutf8(str, 2) != 0)
printf("not ");
printf("ok %d - 2-byte control first\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0x9F, 0x00};
if (verifyutf8(str, 2) != 0)
printf("not ");
printf("ok %d - 2-byte control last\n", ++testcount);
}
{
uint8_t str[] = {0xE0, 0xA0, 0x80, 0x00};
if (verifyutf8(str, 3) != 1)
printf("not ");
printf("ok %d - 3-byte char first codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xEF, 0xBF, 0xBF, 0x00};
if (verifyutf8(str, 3) != 1)
printf("not ");
printf("ok %d - 3-byte char last codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xE0, 0x80, 0x80, 0x00};
if (verifyutf8(str, 3) != 0)
printf("not ");
printf("ok %d - 3-byte char invalid 1\n", ++testcount);
}
{
uint8_t str[] = {0xED, 0xA0, 0xBF, 0x00};
if (verifyutf8(str, 3) != 0)
printf("not ");
printf("ok %d - 3-byte char invalid 2\n", ++testcount);
}
{
uint8_t str[] = {0xF0, 0x90, 0x80, 0x80, 0x00};
if (verifyutf8(str, 4) != 1)
printf("not ");
printf("ok %d - 4-byte char first codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xF4, 0x8F, 0xBF, 0xBF, 0x00};
if (verifyutf8(str, 4) != 1)
printf("not ");
printf("ok %d - 4-byte char first codepoint\n", ++testcount);
}
{
uint8_t str[] = {0xF0, 0x80, 0x80, 0x80, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid 1\n", ++testcount);
}
{
uint8_t str[] = {0xF4, 0x90, 0x80, 0x80, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid 2\n", ++testcount);
}
{
uint8_t str[] = {0xF7, 0xBF, 0xBF, 0xBF, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid 3\n", ++testcount);
}
{
uint8_t str[] = {0xFF, 0xBF, 0xBF, 0xBF, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char all ones\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0x80, 0x00};
if (verifyutf8(str, 1) != 0)
printf("not ");
printf("ok %d - 2-byte char too short\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0x80, 0x80, 0x00};
if (verifyutf8(str, 3) != 0)
printf("not ");
printf("ok %d - 2-byte char too long\n", ++testcount);
}
{
uint8_t str[] = {0xC2, 0x80, 0x00, 0x00};
if (verifyutf8(str, 3) != 0)
printf("not ");
printf("ok %d - invalid after 2-byte char\n", ++testcount);
}
{
uint8_t str[] = {0xF0, 'x', 0x80, 0x80, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid continuation 2nd byte\n", ++testcount);
}
{
uint8_t str[] = {0xF0, 0x90, 'x', 0x80, 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid continuation 3rd byte\n", ++testcount);
}
{
uint8_t str[] = {0xF0, 0x90, 0x80, 'x', 0x00};
if (verifyutf8(str, 4) != 0)
printf("not ");
printf("ok %d - 4-byte char invalid continuation 4th byte\n", ++testcount);
}
{
uint8_t str[] = {'t', 'e', 's', 't', 0xF0, 0x91, 0x82, 0x83, 'x', 'y', 'z', 0x00};
if (verifyutf8(str, 11) != 1)
printf("not ");
printf("ok %d - long string\n", ++testcount);
}
printf("1..%d\n", testcount);
return 0;
}
|