Browse Source

Rise coverage again

Kajetan Johannes Hammerle 2 weeks ago
parent
commit
77a27f7db7

+ 5 - 17
src/ArrayString.cpp

@@ -1,5 +1,7 @@
 #include "core/utils/ArrayString.hpp"
 
+#include <string.h>
+
 #include "core/math/Math.hpp"
 #include "core/utils/Error.hpp"
 
@@ -96,24 +98,11 @@ Error CharString::copyFrom(const CharString& s) {
 }
 
 bool CharString::operator==(const char* s) const {
-    const char* p = data;
-    while(*s == *p && *s != '\0') {
-        s++;
-        p++;
-    }
-    return *s == *p;
+    return strcmp(data, s) == 0;
 }
 
 bool CharString::operator==(const CharString& other) const {
-    if(length != other.getLength()) {
-        return false;
-    }
-    for(int i = 0; i < length; i++) {
-        if(data[i] != other[i]) {
-            return false;
-        }
-    }
-    return true;
+    return length == other.length && strcmp(data, other.data) == 0;
 }
 
 bool CharString::operator!=(const char* s) const {
@@ -217,8 +206,7 @@ Error CharString::print() const {
 
 Error CharString::printLine() const {
     CORE_RETURN_ERROR(print());
-    CORE_RETURN_ERROR(Core::putChar('\n'));
-    return ErrorCode::NONE;
+    return Core::putChar('\n');
 }
 
 bool CharString::startsWidth(const CharString& other, int from) const {

BIN
test/.Test.hpp.swo


+ 3 - 0
test/Main.cpp

@@ -12,6 +12,9 @@ static void onExit(int code, void* data) {
     CORE_TEST_ERROR(s.append("Hello from exit #: #"));
     CORE_TEST_ERROR(s.format(code, i));
     CORE_TEST_ERROR(s.printLine());
+    Core::String8<64> s8;
+    CORE_TEST_ERROR(s8.append("Hello from exit"));
+    CORE_TEST_ERROR(s8.printLine());
     Core::Test::finalize();
 }
 

+ 17 - 0
test/modules/ArrayStringTests.cpp

@@ -20,6 +20,7 @@ static void testEquality8() {
     CORE_TEST_TRUE(s == build("test"));
     CORE_TEST_TRUE("test" == s);
     CORE_TEST_TRUE(build("test") == s);
+    CORE_TEST_FALSE(build("tes2") == s);
     CORE_TEST_TRUE(s == s);
 }
 
@@ -445,6 +446,19 @@ static void testKeepHash8() {
     CORE_TEST_STRING("a # test ## ##123456789", s);
 }
 
+static void testFormatWithoutArguments8() {
+    String8 s;
+    CORE_TEST_ERROR(s.append("wusi"));
+    CORE_TEST_ERROR(s.format());
+    CORE_TEST_STRING("wusi", s);
+}
+
+static void testUnicodeString8() {
+    String8 s;
+    CORE_TEST_ERROR(s.append(U"_üö§äab"));
+    CORE_TEST_STRING("_üö§äab", s);
+}
+
 static String32 build(const c32* cs) {
     String32 s;
     CORE_TEST_ERROR(s.append(cs));
@@ -457,6 +471,7 @@ static void testEquality32() {
     CORE_TEST_TRUE(s == build(U"test"));
     CORE_TEST_TRUE(U"test" == s);
     CORE_TEST_TRUE(build(U"test") == s);
+    CORE_TEST_FALSE(build(U"tes2") == s);
     CORE_TEST_TRUE(s == s);
 }
 
@@ -969,6 +984,8 @@ void Core::testArrayString() {
     testAppendError8();
     testPrint8();
     testKeepHash8();
+    testFormatWithoutArguments8();
+    testUnicodeString8();
 
     testEquality32();
     testUnicodeEquality32();

+ 6 - 0
test/modules/ErrorTests.cpp

@@ -30,4 +30,10 @@ void Core::testError() {
             ErrorCode::SLEEP_INTERRUPTED | ErrorCode::THREAD_ERROR |
             ErrorCode::MUTEX_ERROR | ErrorCode::EXISTING_KEY |
             ErrorCode::CANNOT_OPEN_FILE | ErrorCode::END_OF_FILE);
+
+    char buffer[4];
+    CORE_TEST_EQUAL(
+        ErrorCode::CAPACITY_REACHED,
+        Core::toString(ErrorCode::INVALID_STATE, buffer, sizeof(buffer)));
+    CORE_TEST_STRING("000", buffer);
 }

+ 1 - 0
test/modules/HashedStringTests.cpp

@@ -33,6 +33,7 @@ static void testComparison() {
 static void testLength() {
     HString s("test");
     CORE_TEST_EQUAL(4, s.getLength());
+    CORE_TEST_EQUAL(31, s.getCapacity());
 }
 
 static void testHashCode() {

+ 7 - 0
test/modules/ProbingHashMapTests.cpp

@@ -1,6 +1,7 @@
 #include "../../src/ErrorSimulator.hpp"
 #include "../Tests.hpp"
 #include "core/data/ProbingHashMap.hpp"
+#include "core/utils/Error.hpp"
 
 template struct Core::ProbingHashMap<int, int>;
 using IntMap = Core::ProbingHashMap<int, int>;
@@ -350,6 +351,11 @@ static void testAddCollisions() {
     }
 }
 
+static void testLargeRehash() {
+    IntMap map;
+    CORE_TEST_EQUAL(Core::ErrorCode::CAPACITY_REACHED, map.rehash(1llu << 50));
+}
+
 void Core::testProbingHashMap(bool light, bool outOfMemoryTest) {
     testAdd();
     testMultipleAdd();
@@ -373,4 +379,5 @@ void Core::testProbingHashMap(bool light, bool outOfMemoryTest) {
     }
     testInsertInvalid();
     testAddCollisions();
+    testLargeRehash();
 }