|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2023 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: #include "header.h"
8: #include "mystring.h"
9:
10: // 本物の方を使ってしまうと芋づるでリンクが解決できないのでダミーを用意。
11: class WindrvDevice
12: {
13: public:
14: static bool MatchWildcard(const std::string&, const std::string&);
15: };
16: class Human68k
17: {
18: public:
19: static uint32 Unixtime2DateTime(time_t);
20: static time_t DateTime2Unixtime(uint32);
21: };
22:
23: #define TEST_WINDRV
24: #include "windrv.cpp"
25: #include "test_tool.cpp"
26:
27: static void
28: test_MatchWildcard()
29: {
30: struct {
31: const char *pname;
32: const char *fname;
33: bool expected;
34: } table[] = {
35: // Pattern Name Expected
36: { "?.com", "a.com", true },
37: { "??.com", "a.com", true },
38: { "?.com", "ab.com", false },
39:
40: { "??", "a", true },
41: { "??", "ab", true },
42: { "??", "abc", false },
43:
44: { "?", "a.s", false },
45: { "???", "a.s", false },
46: { "?.?", "a.s", true },
47:
48: { "futype.???", "futype.x", true },
49: { "futype.???", "futype.xy", true },
50: { "futype.???", "futype.xyz", true },
51: { "futype.???", "futype", true },
52: { "futype.???", "abcdef.xxx", false },
53: };
54:
55: for (int i = 0; i < countof(table); i++) {
56: std::string pname(table[i].pname);
57: std::string fname(table[i].fname);
58: bool expected = table[i].expected;
59: char where[256];
60: snprintf(where, sizeof(where), "\"%s\", \"%s\"",
61: pname.c_str(), fname.c_str());
62:
63: bool actual = WindrvDevice::MatchWildcard(fname, pname);
64: xp_eq(expected, actual, where);
65: }
66: }
67:
68: static struct {
69: time_t unixtime;
70: uint32 dostime;
71: } table_time[] = {
72: { 315500400, 0x00210000 }, // 1980-01-01 00:00:00 (+0900 JST)
73: { 1702990056, 0x5793adf2 }, // 2023-12-19 21:47:36 (+0900 JST)
74: };
75:
76: static void
77: test_Unixtime2DateTime()
78: {
79: for (const auto& a : table_time) {
80: time_t utime = a.unixtime;
81: uint32 dtime = a.dostime;
82:
83: auto dtime_actual = Human68k::Unixtime2DateTime(utime);
84: xp_eq(dtime, dtime_actual);
85: }
86:
87: // 1980 年以前は 1980 年に張り付ける
88: xp_eq(0x00210000, Human68k::Unixtime2DateTime(315446400));
89: }
90:
91: static void
92: test_DateTime2Unixtime()
93: {
94: for (const auto& a : table_time) {
95: time_t utime = a.unixtime;
96: uint32 dtime = a.dostime;
97:
98: auto utime_actual = Human68k::DateTime2Unixtime(dtime);
99: xp_eq(utime, utime_actual);
100: }
101: }
102:
103: int
104: main(int ac, char *av[])
105: {
106: test_MatchWildcard();
107: test_Unixtime2DateTime();
108: test_DateTime2Unixtime();
109: return 0;
110: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.