23#include <winpr/path.h>
24#include <winpr/file.h>
25#include <winpr/debug.h>
26#include <winpr/print.h>
28#include "TestFreeRDPHelpers.h"
30static char* get_path(
const char* codec,
const char* type,
const char* name)
32 char path[500] = { 0 };
33 (void)snprintf(path,
sizeof(path),
"%s-%s-%s.bin", codec, type, name);
34 char* s1 = GetCombinedPath(CMAKE_CURRENT_SOURCE_DIR, codec);
38 char* s2 = GetCombinedPath(s1, path);
43static FILE* open_path(
const char* codec,
const char* type,
const char* name,
const char* mode)
49 char* path = get_path(codec, type, name);
52 (void)printf(
"%s: get_path %s %s failed\n", __func__, type, name);
56 FILE* fp = winpr_fopen(path, mode);
59 char buffer[128] = { 0 };
60 (void)printf(
"%s: %s %s: fopen(%s, %s) failed: %s\n", __func__, type, name, path, mode,
61 winpr_strerror(errno, buffer,
sizeof(buffer)));
67void* test_codec_helper_read_data(
const char* codec,
const char* type,
const char* name,
72 WINPR_ASSERT(plength);
78 FILE* fp = open_path(codec, type, name,
"rb");
82 if (_fseeki64(fp, 0, SEEK_END) != 0)
85 const size_t pos = _ftelli64(fp);
87 if (_fseeki64(fp, 0, SEEK_SET) != 0)
94 if (fread(cmp, 1, pos, fp) != pos)
102 (void)printf(
"%s: [%s] %s %s -> %p\n", __func__, codec, type, name, rc);
109void test_codec_helper_write_data(
const char* codec,
const char* type,
const char* name,
110 const void* data,
size_t length)
112 FILE* fp = open_path(codec, type, name,
"wb");
116 if (fwrite(data, 1, length, fp) != length)
123bool test_codec_helper_compare(
const char* codec,
const char* type,
const char* name,
124 const void* data,
size_t length)
128 void* cmp = test_codec_helper_read_data(codec, type, name, &cmplen);
131 if (cmplen != length)
133 (void)printf(
"%s: [%s] %s %s: length mismatch: %" PRIuz
" vs %" PRIuz
"\n", __func__, codec,
134 type, name, cmplen, length);
137 if (memcmp(data, cmp, length) != 0)
139 (void)printf(
"%s: [%s] %s %s: data mismatch\n", __func__, codec, type, name);
140 winpr_HexDump(__func__, WLOG_WARN, data, length);
141 winpr_HexDump(__func__, WLOG_WARN, cmp, cmplen);
146 (void)printf(
"%s: [%s] %s %s -> %s\n", __func__, codec, type, name, rc ?
"SUCCESS" :
"FAILED");