Skip to content

Commit

Permalink
Add: Some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Jun 9, 2020
1 parent ceb8473 commit 6816a40
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 45 deletions.
4 changes: 2 additions & 2 deletions regression/006_vehicle.nml
Expand Up @@ -55,7 +55,7 @@ alternative_sprites(foster_express_set, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "ope

param[0] = 9;

switch(FEAT_ROADVEHS, SELF, switch_length, position_in_consist) {
switch(FEAT_ROADVEHS, SELF, switch_length, d, position_in_consist + d) {
1: return 5;
return 6;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ item(FEAT_ROADVEHS, foster_express_tram, 89) {
misc_flags: bitmask(ROADVEH_FLAG_TRAM); // This is a tram
}
graphics {
length: switch_length;
length: switch_length(0);
default: foster_express_set;
}
}
4 changes: 2 additions & 2 deletions regression/019_switch.nml
Expand Up @@ -13,7 +13,7 @@ switch(FEAT_INDUSTRIES, SELF, return_switch, STORE_PERM(current_year - 1950, 0x0
/* store a value of 4 into the permanent register 0x00, but evaluate current_month
* use the array notation
*/
switch(FEAT_INDUSTRIES, SELF, coal_mine_subtype_switch, [STORE_PERM(4, 0x00), current_month]) {
switch(FEAT_INDUSTRIES, SELF, coal_mine_subtype_switch, a, [STORE_PERM(a, 0x00), current_month]) {
0..10: return string(STR_COALMINE_MONTH_0_10);
13: return_switch; // unreachable
return string(STR_COALMINE_MONTH_11);
Expand All @@ -28,7 +28,7 @@ item(FEAT_INDUSTRIES, coal_mine) {
}
graphics {
extra_text_industry: return string(STR_COALMINE_EXTRA_TEXT);
cargo_subtype_display: coal_mine_subtype_switch;
cargo_subtype_display: coal_mine_subtype_switch(4);
control_special: return extra_callback_info1 & 1; // random with 50% chance
// no default
}
Expand Down
10 changes: 6 additions & 4 deletions regression/033_procedure.nml
Expand Up @@ -6,16 +6,18 @@ grf {
min_compatible_version: 0;
}

switch(FEAT_INDUSTRIES, SELF, dumb_add, a, b, a + b) { return; }

/* some computation that requires registers for intermediate values */
switch(FEAT_INDUSTRIES, SELF, callee, (water_distance+layout_num)*(founder_type+founder_colour1)) {
return;
switch(FEAT_INDUSTRIES, SELF, callee, a, (water_distance+layout_num)*(founder_type+founder_colour1)+a) {
return a + dumb_add(5, a);
}

switch(FEAT_INDUSTRIES, SELF, caller2, (founder_colour2+build_date)*(water_distance+founder_colour1)*(random_bits+callee())*(founder_type+layout_num)*(build_type+counter)) {
switch(FEAT_INDUSTRIES, SELF, caller2, dumb_add(1,dumb_add(founder_colour2, build_date))*(water_distance+founder_colour1)*(random_bits+callee(1))*(founder_type+layout_num)*(build_type+counter)) {
return;
}

switch(FEAT_INDUSTRIES, SELF, caller1, (founder_colour2+build_date)*(random_bits+callee())*(build_type+counter)) {
switch(FEAT_INDUSTRIES, SELF, caller1, (founder_colour2+build_date)*dumb_add(random_bits, callee(0))*(build_type+counter)) {
return;
}

Expand Down
Binary file modified regression/expected/006_vehicle.grf
Binary file not shown.
12 changes: 8 additions & 4 deletions regression/expected/006_vehicle.nfo
Expand Up @@ -24,8 +24,10 @@
4 * 9 0D 00 \D= FF 00 \dx00000009

// Name: switch_length
5 * 23 02 01 FF 89
40 00 \dx000000FF
// d : register 80
5 * 31 02 01 FF 89
7D 80 20 \dxFFFFFFFF // d
\2+ 40 00 \dx000000FF
\b1
\wx8005 \dx00000001 \dx00000001 // 1 .. 1: return 5;
\wx8006 // default: return 6;
Expand Down Expand Up @@ -127,8 +129,10 @@ FF
\wx8000 // Return computed value

// Name: @action3_1
25 * 24 02 01 00 89
7E FF 00 \dxFFFFFFFF // switch_length
25 * 38 02 01 00 89
1A 20 \dx00000000
\2sto 1A 20 \dx00000080
\2r 7E FF 00 \dxFFFFFFFF // switch_length(0)
\b1
\wx00FD \dx0000FFFF \dx0000FFFF // @CB_FAILED01;
\wx00FC // return (8 - var[0x1C, 0, -1])
Expand Down
Binary file modified regression/expected/019_switch.grf
Binary file not shown.
27 changes: 18 additions & 9 deletions regression/expected/019_switch.nfo
Expand Up @@ -5,7 +5,7 @@
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d12
0 * 4 \d13

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
Expand All @@ -27,8 +27,9 @@
\wx8000 // default: return 0;

// Name: coal_mine_subtype_switch
5 * 47 02 0A FF 89
1A 20 \dx00000004
// a : register 80
5 * 48 02 0A FF 89
7D 80 20 \dxFFFFFFFF // a
\2psto 1A 20 \dx00000000
\2r 02 00 \dx000000FF
\b2
Expand All @@ -45,30 +46,38 @@
22 03

// Name: @return_action_0
8 * 13 02 0A FE 89
8 * 30 02 0A FF 89
1A 20 \dx00000004
\2sto 1A 00 \dx00000080
\b1
\wx00FF \dx00000000 \dx00000000 // coal_mine_subtype_switch
\wx00FF // coal_mine_subtype_switch

// Name: @return_action_1
9 * 13 02 0A FE 89
10 00 \dx00000001
\b0
\wx8000 // Return computed value

// Name: @CB_FAILED_PROD
9 * 15 02 0A FD 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00
10 * 15 02 0A FD 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
10 * 23 02 0A FD 89
11 * 23 02 0A FD 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FD // Non-graphics callback, return graphics result

// Name: @action3_0
11 * 43 02 0A FD 89
12 * 43 02 0A FD 89
0C 00 \dx0000FFFF
\b3
\wx00FF \dx00000037 \dx00000037 // coal_mine_subtype_switch;
\wx00FF \dx00000037 \dx00000037 // @return_action_0;
\wx8002 \dx0000003A \dx0000003A // return string(STR_COALMINE_EXTRA_TEXT);
\wx00FE \dx0000003B \dx0000003B // return var[0x10, 0, 1]
\wx00FD // @CB_FAILED0A;

12 * 7 03 0A 01 00 \b0
13 * 7 03 0A 01 00 \b0
\wx00FD // @action3_0;

Binary file modified regression/expected/033_procedure.grf
Binary file not shown.
95 changes: 71 additions & 24 deletions regression/expected/033_procedure.nfo
Expand Up @@ -5,7 +5,7 @@
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d11
0 * 4 \d13

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
Expand All @@ -16,33 +16,71 @@
00
00
2 * 52 08 08 "NML\33" "NML regression test" 00 "A test newgrf testing NML" 00
// Name: dumb_add
// a : register 8A
// b : register 8B
3 * 22 02 0A FF 89
7D 8A 20 \dxFFFFFFFF // a
\2+ 7D 8B 00 \dxFFFFFFFF // b
\b0
\wx8000 // Return computed value

// Name: @return_action_0
4 * 66 02 0A FE 89
1A 20 \dx00000005
\2sto 1A 20 \dx0000008A
\2r 7D 88 20 \dxFFFFFFFF // a
\2sto 1A 20 \dx0000008B
\2r 7E FF 20 \dxFFFFFFFF // dumb_add(5, a)
\2sto 1A 20 \dx00000089
\2r 7D 88 20 \dxFFFFFFFF // a
\2+ 7D 89 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value

// Name: callee
3 * 49 02 0A FF 89
// a : register 88
5 * 67 02 0A FE 89
45 30 \dx00000003
\2+ 45 38 \dx0000000F
\2sto 1A 20 \dx00000084
\2sto 1A 20 \dx00000089
\2r 43 20 \dxFFFFFFFF
\2+ 44 20 \dx000000FF
\2* 7D 84 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value
\2* 7D 89 20 \dxFFFFFFFF
\2+ 7D 88 00 \dxFFFFFFFF // a
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FE // default: return (a + dumb_add(5, a))

// Name: caller2
4 * 137 02 0A FE 89
6 * 230 02 0A FD 89
B3 20 \dx00000003
\2+ AA 20 \dx0000FFFF
\2sto 1A 20 \dx00000080
\2r 45 30 \dx00000003
\2+ 44 20 \dx000000FF
\2sto 1A 20 \dx00000081
\2r 7E FF 20 \dxFFFFFFFF // callee
\2r 1A 20 \dx00000001
\2sto 1A 20 \dx00000088
\2r 7E FE 20 \dxFFFFFFFF // callee(1)
\2+ 5F 28 \dx0000FFFF
\2sto 1A 20 \dx00000082
\2r 43 20 \dxFFFFFFFF
\2+ 45 38 \dx0000000F
\2sto 1A 20 \dx00000083
\2r 1A 20 \dx00000001
\2sto 1A 20 \dx00000086
\2r 45 3C \dx0000000F
\2+ 46 20 \dxFFFFFFFF
\2sto 1A 20 \dx0000008A
\2r 46 20 \dxFFFFFFFF
\2sto 1A 20 \dx0000008B
\2r 7E FF 20 \dxFFFFFFFF // dumb_add(var[0x45, 28, 15], var[0x46, 0, -1])
\2sto 1A 20 \dx00000087
\2r 1A 20 \dx00000086
\2sto 1A 20 \dx0000008A
\2r 1A 20 \dx00000087
\2sto 1A 20 \dx0000008B
\2r 7E FF 20 \dxFFFFFFFF // dumb_add(1, dumb_add(var[0x45, 28, 15], var[0x46, 0, -1]))
\2* 7D 83 20 \dxFFFFFFFF
\2* 7D 82 20 \dxFFFFFFFF
\2* 7D 81 20 \dxFFFFFFFF
Expand All @@ -51,46 +89,55 @@ B3 20 \dx00000003
\wx8000 // Return computed value

// Name: caller1
5 * 79 02 0A FF 89
7 * 143 02 0A FF 89
B3 20 \dx00000003
\2+ AA 20 \dx0000FFFF
\2sto 1A 20 \dx00000080
\2r 7E FF 20 \dxFFFFFFFF // callee
\2+ 5F 28 \dx0000FFFF
\2sto 1A 20 \dx00000081
\2r 5F 28 \dx0000FFFF
\2sto 1A 20 \dx00000083
\2r 1A 20 \dx00000000
\2sto 1A 20 \dx00000088
\2r 7E FE 20 \dxFFFFFFFF // callee(0)
\2sto 1A 20 \dx00000084
\2r 1A 20 \dx00000083
\2sto 1A 20 \dx0000008A
\2r 1A 20 \dx00000084
\2sto 1A 20 \dx0000008B
\2r 7E FF 20 \dxFFFFFFFF // dumb_add(var[0x5F, 8, 65535], callee(0))
\2sto 1A 20 \dx00000085
\2r 45 3C \dx0000000F
\2+ 46 20 \dxFFFFFFFF
\2* 7D 81 20 \dxFFFFFFFF
\2* 7D 85 20 \dxFFFFFFFF
\2* 7D 80 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value

6 * 11 00 0A \b2 01 FF \wx0000
8 * 11 00 0A \b2 01 FF \wx0000
08 00
09 00

7 * 11 00 0A \b2 01 FF \wx0000
9 * 11 00 0A \b2 01 FF \wx0000
21 00
22 42

// Name: @CB_FAILED_PROD
8 * 15 02 0A FD 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00
10 * 15 02 0A FE 00 \wx0000 \wx0000 \wx0000 \wx0000 \wx0000 00

// Name: @CB_FAILED0A
9 * 23 02 0A FD 89
11 * 23 02 0A FE 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FD // Non-graphics callback, return graphics result
\wx00FE // Non-graphics callback, return graphics result

// Name: @action3_0
10 * 33 02 0A FD 89
12 * 33 02 0A FE 89
0C 00 \dx0000FFFF
\b2
\wx00FE \dx0000003B \dx0000003B // caller2;
\wx00FD \dx0000003B \dx0000003B // caller2;
\wx00FF \dx0000015F \dx0000015F // caller1;
\wx00FD // @CB_FAILED0A;
\wx00FE // @CB_FAILED0A;

11 * 7 03 0A 01 00 \b0
\wx00FD // @action3_0;
13 * 7 03 0A 01 00 \b0
\wx00FE // @action3_0;

0 comments on commit 6816a40

Please sign in to comment.