blob: 39d7a8304f261336b8c2a0cb2432cc144378af2d (
plain)
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
|
#include <EmbeddedResource.h>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <string_view>
DECLARE_RESOURCE_COLLECTION(testdata1);
DECLARE_RESOURCE_COLLECTION(testdata2);
DECLARE_RESOURCE_COLLECTION(testdata3);
DECLARE_RESOURCE(testdata3, main_cpp);
void verify_resource(ResourceLoader const& r)
{
if (r.name() == L"main.cpp")
{
#ifdef __cpp_lib_span
if (r.template data<uint8_t>().size() != MAIN_CPP_FILE_SIZE) { throw std::runtime_error("r.data.len() != MAIN_CPP_FILE_SIZE"); }
#endif
#ifdef __cpp_lib_string_view
if (r.string().size() != MAIN_CPP_FILE_SIZE) { throw std::runtime_error("r.string().size() != MAIN_CPP_FILE_SIZE"); }
#endif
}
else if (r.name() == L"CMakeLists.txt")
{
#ifdef __cpp_lib_span
if (r.template data<uint8_t>().size() != CMAKELISTS_TXT_FILE_SIZE)
{
throw std::runtime_error("r.data.len() != CMAKELISTS_TXT_FILE_SIZE");
}
#endif
#ifdef __cpp_lib_string_view
if (r.string().size() != CMAKELISTS_TXT_FILE_SIZE) { throw std::runtime_error("r.string().size() != CMAKELISTS_TXT_FILE_SIZE"); }
#endif
}
else { throw std::runtime_error("Unknown resource name"); }
}
int main(int argc, char* argv[])
try
{
std::string_view res = LOAD_RESOURCE(testdata3, main_cpp).data;
if (res.size() != MAIN_CPP_FILE_SIZE) { throw std::runtime_error("r.data.len() != MAIN_CPP_FILE_SIZE"); }
auto resourceCollection1 = LOAD_RESOURCE_COLLECTION(testdata1);
for (auto const r : resourceCollection1) { verify_resource(r); }
auto resourceCollection2 = LOAD_RESOURCE_COLLECTION(testdata2);
for (auto const r : resourceCollection2) { verify_resource(r); }
auto resourceCollection3 = LOAD_RESOURCE_COLLECTION(testdata3);
for (auto const r : resourceCollection2) { verify_resource(r); }
return 0;
} catch (const std::exception& ex)
{
std::cerr << "Failed: " << ex.what() << std::endl;
return -1;
}
|