Ryujinx-SDL/test/testiconv.c
Sylvain Becker fb0ce375f0 Cleanup add brace (#6545)
* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line

(cherry picked from commit 6a2200823c66e53bd3cda4a25f0206b834392652 to reduce conflicts merging between SDL2 and SDL3)
2022-11-28 12:33:03 -08:00

98 lines
2.5 KiB
C

/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* quiet windows compiler warnings */
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include "SDL.h"
#include "testutils.h"
static size_t
widelen(char *data)
{
size_t len = 0;
Uint32 *p = (Uint32 *) data;
while (*p++) {
++len;
}
return len;
}
int
main(int argc, char *argv[])
{
const char *formats[] = {
"UTF8",
"UTF-8",
"UTF16BE",
"UTF-16BE",
"UTF16LE",
"UTF-16LE",
"UTF32BE",
"UTF-32BE",
"UTF32LE",
"UTF-32LE",
"UCS4",
"UCS-4",
};
char * fname;
char buffer[BUFSIZ];
char *ucs4;
char *test[2];
int i;
FILE *file;
int errors = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt");
file = fopen(fname, "rb");
if (file == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
return 1;
}
SDL_free(fname);
while (fgets(buffer, sizeof(buffer), file)) {
/* Convert to UCS-4 */
size_t len;
ucs4 =
SDL_iconv_string("UCS-4", "UTF-8", buffer,
SDL_strlen(buffer) + 1);
len = (widelen(ucs4) + 1) * 4;
for (i = 0; i < SDL_arraysize(formats); ++i) {
test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "FAIL: %s\n", formats[i]);
++errors;
}
SDL_free(test[0]);
SDL_free(test[1]);
}
test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
SDL_free(ucs4);
fputs(test[0], stdout);
SDL_free(test[0]);
}
fclose(file);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Total errors: %d\n", errors);
return errors ? errors + 1 : 0;
}