edify: Some clean-ups to libedify.
- Remove dead declarations in expr.h: SetError(), GetError(),
ClearError().
- Remove the declaration of Build() out of expr.h.
- Use std::unordered_map to implement RegisterFunction() and
FindFunction(); kill FinishRegistration().
- Add a testcase for calling unknown functions.
Test: mmma bootable/recovery; recovery_component_test passes.
Change-Id: I9af6825ae677f92b22d716a4a5682f58522af03b
diff --git a/tests/component/edify_test.cpp b/tests/component/edify_test.cpp
index ede2ecb..a4dbb9f 100644
--- a/tests/component/edify_test.cpp
+++ b/tests/component/edify_test.cpp
@@ -22,17 +22,18 @@
static void expect(const char* expr_str, const char* expected) {
Expr* e;
- int error_count;
- EXPECT_EQ(parse_string(expr_str, &e, &error_count), 0);
+ int error_count = 0;
+ EXPECT_EQ(0, parse_string(expr_str, &e, &error_count));
+ EXPECT_EQ(0, error_count);
State state(expr_str, nullptr);
char* result = Evaluate(&state, e);
if (expected == nullptr) {
- EXPECT_EQ(result, nullptr);
+ EXPECT_EQ(nullptr, result);
} else {
- EXPECT_STREQ(result, expected);
+ EXPECT_STREQ(expected, result);
}
free(result);
@@ -42,7 +43,6 @@
protected:
virtual void SetUp() {
RegisterBuiltins();
- FinishRegistration();
}
};
@@ -149,3 +149,21 @@
expect(std::string(8192, 's').c_str(), std::string(8192, 's').c_str());
}
+TEST_F(EdifyTest, unknown_function) {
+ // unknown function
+ const char* script1 = "unknown_function()";
+ Expr* expr;
+ int error_count = 0;
+ EXPECT_EQ(1, parse_string(script1, &expr, &error_count));
+ EXPECT_EQ(1, error_count);
+
+ const char* script2 = "abc; unknown_function()";
+ error_count = 0;
+ EXPECT_EQ(1, parse_string(script2, &expr, &error_count));
+ EXPECT_EQ(1, error_count);
+
+ const char* script3 = "unknown_function1() || yes";
+ error_count = 0;
+ EXPECT_EQ(1, parse_string(script3, &expr, &error_count));
+ EXPECT_EQ(1, error_count);
+}
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index bd6534b..64a6b37 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -54,7 +54,6 @@
virtual void SetUp() {
RegisterBuiltins();
RegisterInstallFunctions();
- FinishRegistration();
}
};