Skip to content

Commit 8749847

Browse files
committed
add invalid format error
1 parent 3f0ac63 commit 8749847

File tree

6 files changed

+111
-27
lines changed

6 files changed

+111
-27
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "../../../schema/testcase.schema.json",
3+
"target": {
4+
"start": {
5+
"label": "check_collision"
6+
}
7+
},
8+
"cases": {
9+
"array as number": {
10+
"setup": {
11+
"register": {
12+
"A": {
13+
"address": []
14+
}
15+
}
16+
},
17+
"expected": {}
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "../../../schema/testcase.schema.json",
3+
"target": {
4+
"start": {
5+
"label": "check_collision"
6+
}
7+
},
8+
"cases": {
9+
"unknown radix": {
10+
"setup": {
11+
"register": {
12+
"A": {
13+
"address": "#address"
14+
}
15+
}
16+
},
17+
"expected": {}
18+
}
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "../../../schema/testcase.schema.json",
3+
"target": {
4+
"start": {
5+
"label": "check_collision"
6+
}
7+
},
8+
"cases": {
9+
"unknown type": {
10+
"setup": {
11+
"memory": [
12+
{
13+
"address": "$00",
14+
"value": {
15+
"address": "$00",
16+
"type": "xxx"
17+
}
18+
}
19+
]
20+
},
21+
"expected": {}
22+
}
23+
}
24+
}

include/enum/value_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace std;
88
enum class value_type
99
{
1010
// Value
11-
VALUE,
11+
VALUE = 1,
1212
// High byte
1313
HIBYTE,
1414
// Low byte

src/test/test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,23 @@ test_result test::do_test(string id, json testcase)
7070

7171
return assert.get_result(id);
7272
}
73+
catch (invalid_argument &e)
74+
{
75+
test_result result;
76+
result.set_id(id);
77+
stringstream ss;
78+
ss << e.what() << endl;
79+
ss << endl;
80+
result.add_error(ss.str());
81+
return result;
82+
}
7383
catch (cpu_runtime_error &e)
7484
{
7585
test_result result;
7686
result.set_id(id);
7787
stringstream ss;
7888
ss << e.what() << endl;
89+
ss << endl;
7990
result.add_error(ss.str());
8091
return result;
8192
}

src/util/value_convert.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,45 @@ uint16_t value_convert::parse_json_number(emulation_devices *device, json value)
2121
{
2222
switch (value.type())
2323
{
24-
case json::value_t::number_integer:
25-
case json::value_t::number_unsigned:
26-
return value.get<uint16_t>();
27-
case json::value_t::string:
28-
{
29-
string str = value.get<string>();
30-
if (str.compare(0, 1, "$") == 0)
31-
return stoi(str.substr(1), 0, 16);
32-
else if (str.compare(0, 1, "%") == 0)
33-
return stoi(str.substr(1), 0, 2);
34-
}
35-
case json::value_t::object:
36-
auto address = get_address(device, value);
37-
if (value["type"].is_null())
38-
return device->get_memory()->read(address);
39-
switch(value_name_type_map[value["type"].get<string>()])
24+
case json::value_t::number_integer:
25+
case json::value_t::number_unsigned:
26+
return value.get<uint16_t>();
27+
case json::value_t::string:
4028
{
41-
case value_type::VALUE:
29+
string str = value.get<string>();
30+
if (str.compare(0, 1, "$") == 0)
31+
return stoi(str.substr(1), 0, 16);
32+
else if (str.compare(0, 1, "%") == 0)
33+
return stoi(str.substr(1), 0, 2);
34+
break;
35+
}
36+
case json::value_t::object:
37+
{
38+
auto address = get_address(device, value);
39+
if (value["type"].is_null())
4240
return device->get_memory()->read(address);
43-
case value_type::HIBYTE:
44-
return address >> 8;
45-
case value_type::LOBYTE:
46-
return address & 0xFF;
47-
case value_type::RTS_HIBYTE:
48-
return (address - 1) >> 8;
49-
case value_type::RTS_LOBYTE:
50-
return (address - 1) & 0xFF;
41+
42+
if (value["type"].is_string())
43+
switch (value_name_type_map[value["type"].get<string>()])
44+
{
45+
case value_type::VALUE:
46+
return device->get_memory()->read(address);
47+
case value_type::HIBYTE:
48+
return address >> 8;
49+
case value_type::LOBYTE:
50+
return address & 0xFF;
51+
case value_type::RTS_HIBYTE:
52+
return (address - 1) >> 8;
53+
case value_type::RTS_LOBYTE:
54+
return (address - 1) & 0xFF;
55+
}
56+
break;
5157
}
58+
case json::value_t::null:
59+
return 0;
5260
}
53-
return 0;
61+
62+
throw invalid_argument("Invalid format: " + to_string(value));
5463
}
5564

5665
uint16_t value_convert::to_two_complement_byte(emulation_devices *device, json value)

0 commit comments

Comments
 (0)