107 lines
3.6 KiB
C++
107 lines
3.6 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
|
* @license MPL-2 (see license file)
|
|
*/
|
|
#include <test-debug/debug.hpp>
|
|
#include <etest/etest.hpp>
|
|
#include "testInterface.hpp"
|
|
|
|
|
|
TEST(testIf, direct_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = false; if (true) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
|
|
TEST(testIf, direct_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = false; if (false) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
}
|
|
|
|
TEST(testIf, direct_3) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = false; if (true) result = true;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
|
|
TEST(testIf, direct_4) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = false; if (false) result = true;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
}
|
|
|
|
TEST(testIf, else_case_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (false) { result = 1;} else { result = 2;}");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 2);
|
|
}
|
|
TEST(testIf, else_case_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (false) result = 1; else result = 2;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 2);
|
|
}
|
|
|
|
TEST(testIf, else_else_case) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (false) { result = 1;} else if (false) { result = 2;} else { result = 3;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 3);
|
|
}
|
|
|
|
TEST(testIf, variable_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable a = true; variable result = false; if (a) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
|
|
TEST(testIf, variable_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable a = false; variable result = false; if (a) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
}
|
|
|
|
TEST(testIf, compare_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable a = 111; variable b = 333; variable result = false; if (a != b) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
|
|
TEST(testIf, compare_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable a = 111; variable b = 333; variable result = false; if (a == b) { result = true;};");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
} |