From 8d2d31514295a2d0eff5971887246f6d4211fc6d Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Thu, 28 Mar 2013 15:51:38 +0100 Subject: Added code to parse properties and to find correct configuration files from c++ part of plugin. --- tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc') 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 + +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); +} -- cgit v1.2.3