Skip to content

Commit 7ccb4c6

Browse files
committed
Update VirtualMachine::reset() test
1 parent 635e942 commit 7ccb4c6

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

test/virtual_machine/virtual_machine_test.cpp

+41-3
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,21 @@ unsigned int testFunction5(VirtualMachine *vm)
13271327
return 0;
13281328
}
13291329

1330+
unsigned int testFunction6(VirtualMachine *vm)
1331+
{
1332+
vm->addReturnValue(0);
1333+
vm->stop(true, false, false);
1334+
return 1;
1335+
}
1336+
1337+
unsigned int testFunction7(VirtualMachine *vm)
1338+
{
1339+
vm->addReturnValue(0);
1340+
vm->stop(true, false, false);
1341+
vm->reset();
1342+
return 1;
1343+
}
1344+
13301345
TEST(VirtualMachineTest, OP_EXEC)
13311346
{
13321347
static unsigned int bytecode[] = {
@@ -1518,18 +1533,41 @@ TEST(VirtualMachineTest, OP_WARP)
15181533

15191534
TEST(VirtualMachineTest, Reset)
15201535
{
1521-
static unsigned int bytecode[] = { OP_START, OP_NULL, OP_EXEC, 0, OP_HALT };
1522-
static BlockFunc functions[] = { &testFunction3 };
1536+
static unsigned int bytecode1[] = { OP_START, OP_NULL, OP_EXEC, 0, OP_HALT };
1537+
static unsigned int bytecode2[] = { OP_START, OP_NULL, OP_EXEC, 1, OP_HALT };
1538+
static BlockFunc functions[] = { &testFunction6, &testFunction7 };
15231539

15241540
VirtualMachine vm;
1525-
vm.setBytecode(bytecode);
1541+
vm.setBytecode(bytecode1);
15261542
vm.setFunctions(functions);
1543+
15271544
vm.run();
15281545
ASSERT_FALSE(vm.atEnd());
1546+
ASSERT_EQ(vm.registerCount(), 1);
15291547
vm.reset();
1548+
ASSERT_EQ(vm.registerCount(), 0);
15301549
ASSERT_FALSE(vm.atEnd());
15311550
vm.run();
15321551
ASSERT_FALSE(vm.atEnd());
15331552
vm.run();
15341553
ASSERT_TRUE(vm.atEnd());
1554+
1555+
vm.reset();
1556+
ASSERT_FALSE(vm.atEnd());
1557+
1558+
vm.setBytecode(bytecode2);
1559+
1560+
vm.run();
1561+
ASSERT_FALSE(vm.atEnd());
1562+
ASSERT_EQ(vm.registerCount(), 1);
1563+
vm.reset();
1564+
ASSERT_EQ(vm.registerCount(), 0);
1565+
ASSERT_FALSE(vm.atEnd());
1566+
vm.run();
1567+
ASSERT_FALSE(vm.atEnd());
1568+
vm.run();
1569+
ASSERT_TRUE(vm.atEnd());
1570+
1571+
vm.reset();
1572+
ASSERT_FALSE(vm.atEnd());
15351573
}

0 commit comments

Comments
 (0)