aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-03-28 15:51:38 +0100
committerJiri Vanek <[email protected]>2013-03-28 15:51:38 +0100
commit8d2d31514295a2d0eff5971887246f6d4211fc6d (patch)
treed66ce4fb57c823a2aa8894bb6894b33bdbe162f6 /tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc
parent58b4d6e3dc3a95cfbc6f369287aca04763522e48 (diff)
Added code to parse properties and to find correct configuration files from c++ part of plugin.
Diffstat (limited to 'tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc')
-rw-r--r--tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc
index 1ad1698..dc16bd2 100644
--- a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc
+++ b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc
@@ -42,6 +42,10 @@
#include "IcedTeaPluginUtils.h"
#include "IcedTeaNPPlugin.h"
+#include <fstream>
+
+extern void trim(std::string& str);
+extern bool file_exists(std::string filename);
TEST(NPVariantAsString) {
NPVariant var;
@@ -82,3 +86,39 @@ TEST(NPVariantStringCopy) {
CHECK_EQUAL(0, browsermock_unfreed_allocations());
}
+
+TEST(trim) {
+ std::string toBeTrimmed = std::string(" testX ");
+ IcedTeaPluginUtilities::trim (toBeTrimmed);
+ CHECK_EQUAL("testX", toBeTrimmed);
+
+ std::string toBeTrimmed2 = std::string(" \t testX\n");
+ IcedTeaPluginUtilities::trim (toBeTrimmed2);
+ CHECK_EQUAL("testX", toBeTrimmed2);
+
+ std::string toBeTrimmed3 = std::string(" \t \n te \n stX\n");
+ IcedTeaPluginUtilities::trim (toBeTrimmed3);
+ CHECK_EQUAL("te \n stX", toBeTrimmed3);
+}
+
+
+/* Creates a temporary file with the specified contents */
+static std::string temporary_file(const std::string& contents) {
+ std::string path = tmpnam(NULL); /* POSIX function, fine for test suite */
+ std::ofstream myfile;
+ myfile.open (path.c_str());
+ myfile << contents;
+ myfile.close();
+ return path;
+}
+
+
+TEST(file_exists) {
+ std::string f1 = temporary_file("dummy content");
+ bool a = IcedTeaPluginUtilities::file_exists(f1);
+ CHECK_EQUAL(a, true);
+
+ remove(f1.c_str());
+ bool b = IcedTeaPluginUtilities::file_exists(f1);
+ CHECK_EQUAL(b, false);
+}