Added tests for string modify and shift functions.
authorArjen Baart <arjen@andromeda.nl>
Thu, 14 May 2020 15:35:10 +0000 (17:35 +0200)
committerArjen Baart <arjen@andromeda.nl>
Thu, 14 May 2020 15:35:10 +0000 (17:35 +0200)
configure.ac
src/Makefile.am
src/String.h
src/_version.c [new file with mode: 0644]
test/Makefile.am
test/string_modify.cpp [new file with mode: 0644]
test/string_modify.exp [new file with mode: 0644]
test/string_shift.cpp [new file with mode: 0644]
test/string_shift.exp [new file with mode: 0644]

index 302db0b..42606d2 100644 (file)
@@ -5,6 +5,7 @@ AC_PREREQ([2.69])
 AC_INIT([libACL], [0.3], [arjen@androemda.nl])
 AC_CONFIG_SRCDIR([src/date.cpp])
 AM_INIT_AUTOMAKE
+AC_LANG(C++)
 AC_CONFIG_MACRO_DIRS([m4])
 AC_CONFIG_FILES([Makefile src/Makefile test/Makefile doc/Makefile])
 AC_CONFIG_HEADERS([config.h])
index 19b99dd..1371d53 100644 (file)
@@ -4,8 +4,9 @@ libACL_la_SOURCES = string.cpp regex.cpp date.cpp parsedate.c dateyacc.y datelex
                     hour.cpp utc.cpp \
                     Integer.cpp \
                     xml.cpp \
-                    configuration.cpp
+                    configuration.cpp \
+                    _version.c
 
-libACL_la_LDFLAGS = -version-info 0:3:0
+libACL_la_LDFLAGS = -release 0.3.1
 
 include_HEADERS = String.h date.h Integer.h xml.h configuration.h
index 195f88a..118d855 100644 (file)
@@ -216,6 +216,7 @@ public:
     */
 
    friend std::ostream& operator<<(std::ostream &, const String &);
+   // Read one line and remove the trailing line feed.
    friend std::istream& operator>>(std::istream &, String &);
 
    /*
diff --git a/src/_version.c b/src/_version.c
new file mode 100644 (file)
index 0000000..549c6ea
--- /dev/null
@@ -0,0 +1,4 @@
+int ACL_Version()
+{
+   return 3;
+}
index f9e14b7..a21b337 100644 (file)
@@ -2,7 +2,7 @@ TESTS = $(check_PROGRAMS) date_today hour_now check_output
 
 AM_CPPFLAGS = -I../src
 LDADD = ../src/.libs/libACL.la
-check_PROGRAMS = string_assign string_basics string_compare string_cat string_substring string_regex \
+check_PROGRAMS = string_assign string_basics string_compare string_cat string_modify string_shift string_substring string_regex \
                  date_assign date_parse date_compare date_arithmetic date_attributes date_check_today \
                  hour_assign hour_parse hour_compare hour_arithmetic hour_check_now \
                  utc_assign utc_parse utc_compare utc_arithmetic utc_convert \
@@ -14,6 +14,8 @@ string_assign_SOURCES      = string_assign.cpp
 string_basics_SOURCES      = string_basics.cpp
 string_compare_SOURCES     = string_compare.cpp
 string_cat_SOURCES         = string_cat.cpp
+string_modify_SOURCES      = string_modify.cpp
+string_shift_SOURCES       = string_shift.cpp
 string_substring_SOURCES   = string_substring.cpp
 string_regex_SOURCES       = string_regex.cpp
 
diff --git a/test/string_modify.cpp b/test/string_modify.cpp
new file mode 100644 (file)
index 0000000..c7b214b
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************
+ *  Unit test for the String class
+ *
+ * test modification operations
+ ******************************************************
+ *
+ */
+
+#include "String.h"
+#include <assert.h>
+
+int main()
+{
+
+   // Upper and lower case conversion
+
+   String s1 = "Abc-12.3dE";
+
+   String s2 = s1.upper();
+   std::cout << s1 << " converted to upper case is" << s2 << "\n";
+   assert(s2 == "ABC-12.3DE");
+
+   String s3 = s1.lower();
+   std::cout << s1 << " converted to lower case is" << s3 << "\n";
+   assert(s3 == "abc-12.3de");
+   assert(s3.upper() == s2);
+
+   // Escaping special characters
+
+   String s4 = "\a\b\f\n\r\t\v\"'\\\xC0\x02";
+   String s5 = s4.escape();
+   std::cout << "Escaped sequence = " << s5 << "\n";
+   assert (s5.unescape() == s4);
+
+
+   return 0;
+}
+
diff --git a/test/string_modify.exp b/test/string_modify.exp
new file mode 100644 (file)
index 0000000..9803275
--- /dev/null
@@ -0,0 +1,4 @@
+Abc-12.3dE converted to upper case isABC-12.3DE
+Abc-12.3dE converted to lower case isabc-12.3de
+Escaped sequence = \a\b\f\n\r\t\v\"\'\\\xC0\x02
+PASS string_modify (exit status: 0)
diff --git a/test/string_shift.cpp b/test/string_shift.cpp
new file mode 100644 (file)
index 0000000..f8c8a0f
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************
+ *  Unit test for the String class
+ *
+ * test string shift operations
+ ******************************************************
+ *
+ */
+
+#include "String.h"
+#include <assert.h>
+
+int main()
+{
+
+   String s1 = "abcdefghij";
+
+   String s2 = s1 << 3;
+   std::cout << s1 << " << 3 = " << s2 << "\n";
+   assert(s2 == "defghij");
+
+   String s3 = s1 >> 3;
+   std::cout << s1 << " >> 3 = " << s3 << "\n";
+   assert(s3 == "abcdefg");
+
+   String s4 = "abcdefghij";
+   std::cout << s4 << " <<= 5 : ";
+   s4 <<= 5;
+   std::cout << s4 << "\n";
+   assert(s4 == "fghij");
+
+   String s5 = "abcdefghij";
+   std::cout << s5 << " >>= 5 : ";
+   s5 >>= 5;
+   std::cout << s5 << "\n";
+   assert(s5 == "abcde");
+
+   return 0;
+}
+
diff --git a/test/string_shift.exp b/test/string_shift.exp
new file mode 100644 (file)
index 0000000..c280a95
--- /dev/null
@@ -0,0 +1,5 @@
+abcdefghij << 3 = defghij
+abcdefghij >> 3 = abcdefg
+abcdefghij <<= 5 : fghij
+abcdefghij >>= 5 : abcde
+PASS string_shift (exit status: 0)