Go to the documentation of this file.00001 #include <boost/test/auto_unit_test.hpp>
00002
00003 #include "testsuite.hh"
00004 #include <utilmm/auto_flag.hh>
00005 #include <utilmm/stringtools.hh>
00006 using namespace utilmm;
00007
00008 BOOST_AUTO_TEST_CASE( test_autoflag )
00009 {
00010 bool flag = false;
00011
00012 { auto_flag<bool> guard(flag, true, true);
00013 BOOST_REQUIRE( flag );
00014 }
00015 BOOST_REQUIRE( !flag );
00016
00017 { auto_flag<bool> guard(flag, false, true);
00018 BOOST_REQUIRE( !flag );
00019 }
00020 BOOST_REQUIRE( !flag );
00021
00022 { auto_flag<bool> guard(flag, false, false);
00023 BOOST_REQUIRE( !flag );
00024 }
00025 BOOST_REQUIRE( flag );
00026
00027 int field = 1;
00028 { auto_flag<int> guard(field, 2, true, true);
00029 BOOST_REQUIRE(field & 2 == 2);
00030 }
00031 BOOST_REQUIRE(field == 1);
00032
00033 { auto_flag<int> guard(field, 1, false, true);
00034 BOOST_REQUIRE(field == 0);
00035 }
00036 BOOST_REQUIRE(field == 1);
00037
00038 { auto_flag<int> guard(field, 2, false, false);
00039 BOOST_REQUIRE(field == 1);
00040 }
00041 BOOST_REQUIRE(field == 3);
00042 }
00043
00044 BOOST_AUTO_TEST_CASE( test_stringlist )
00045 {
00046 using std::string;
00047
00048 {
00049 string a = "a b c";
00050 stringlist l = split(a);
00051
00052 BOOST_REQUIRE_EQUAL(3U, l.size());
00053 BOOST_REQUIRE_EQUAL("a", l.front());
00054 BOOST_REQUIRE_EQUAL("c", l.back());
00055 BOOST_REQUIRE_EQUAL("a b c", join(l));
00056 }
00057
00058 {
00059 string id = "a_b_c";
00060 stringlist l = split(id, "_");
00061 BOOST_REQUIRE_EQUAL(3U, l.size());
00062 BOOST_REQUIRE_EQUAL("abc", join(l, ""));
00063 }
00064
00065 {
00066 string id = "a_b c";
00067 BOOST_REQUIRE_EQUAL("A_B C", upcase(id));
00068 }
00069
00070 {
00071 string match = "do begins with bla";
00072 string nomatch = "does not begins with bla";
00073 string seed = "do begins";
00074 BOOST_REQUIRE(starts_with(match, seed));
00075 BOOST_REQUIRE(!starts_with(nomatch, seed));
00076 }
00077 }
00078
00079 BOOST_AUTO_TEST_CASE( test_clean_path )
00080 {
00081 using std::string;
00082 using boost::filesystem::path;
00083 path p = clean_path("a/../b");
00084 BOOST_REQUIRE_EQUAL("b", p.native_file_string());
00085 p = clean_path("a//b");
00086 BOOST_REQUIRE_EQUAL("a/b", p.native_file_string());
00087 p = clean_path("a/./b");
00088 BOOST_REQUIRE_EQUAL("a/b", p.native_file_string());
00089 p = clean_path("//a/./b//");
00090 BOOST_REQUIRE_EQUAL("/a/b/.", p.native_file_string());
00091 }