summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile14
-rw-r--r--tests/test-diff.cpp199
-rw-r--r--tests/test-qrcode.cpp140
-rw-r--r--tests/test-webchat.cpp (renamed from tests/test-whiteboard.cpp)0
4 files changed, 3 insertions, 350 deletions
diff --git a/tests/Makefile b/tests/Makefile
index f3ec6c8..44c884a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -11,15 +11,13 @@ CXXFLAGS+=--coverage
LDFLAGS+=--coverage
endif
-UNITS=storage.cpp config.cpp compiledsql.cpp qrcode.cpp whiteboard.cpp connectionregistry.cpp diff.cpp
+UNITS=storage.cpp config.cpp compiledsql.cpp webchat.cpp connectionregistry.cpp
UNITTESTS=test-config.cpp \
test-storage.cpp \
test-connectionregistry.cpp \
test-compiledsql.cpp \
- test-qrcode.cpp \
- test-whiteboard.cpp \
- test-diff.cpp
+ test-webchat.cpp
CXXFLAGS+=\
-I/usr/src/googletest/googletest/include \
@@ -54,19 +52,13 @@ config.o: ../config.cpp
connectionregistry.o: ../connectionregistry.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
-diff.o: ../diff.cpp
- $(CXX) $(CXXFLAGS) -o $@ -c $<
-
storage.o: ../storage.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
compiledsql.o: ../compiledsql.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
-whiteboard.o: ../whiteboard.cpp
- $(CXX) $(CXXFLAGS) -o $@ -c $<
-
-qrcode.o: ../qrcode.cpp
+webchat.o: ../webchat.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
libgmock.a:
diff --git a/tests/test-diff.cpp b/tests/test-diff.cpp
deleted file mode 100644
index d09c58e..0000000
--- a/tests/test-diff.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-#include <gtest/gtest.h>
-
-#include <filesystem>
-#include <string>
-#include <system_error>
-
-#include <stdlib.h>
-
-#include <boost/property_tree/ptree.hpp>
-
-#include "libreichwein/file.h"
-
-#include "diff.h"
-
-namespace fs = std::filesystem;
-namespace pt = boost::property_tree;
-using namespace Reichwein;
-
-class DiffTest: public ::testing::Test
-{
-protected:
- DiffTest(){
- }
-
- ~DiffTest(){
- }
-};
-
-TEST_F(DiffTest, constructor)
-{
- // empty constructor
- {
- Diff d{};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data/></diff>");
- }
-
- // constructor via xml diff
- {
- EXPECT_THROW(Diff d{""}, std::exception);
- }
- {
- EXPECT_THROW(Diff d{"<diff><begin></begin></diff>"}, std::exception);
- EXPECT_THROW(Diff d{"<diff><end>0</end><data>abc</data></diff>"}, std::exception);
- EXPECT_THROW(Diff d{"<diff><start>0</start><data>abc</data></diff>"}, std::exception);
- EXPECT_THROW(Diff d{"<diff><start>0</start><end>0</end></diff>"}, std::exception);
- EXPECT_THROW(Diff d{"<diff><start>5</start><end>0</end><data>abc</data></diff>"}, std::exception);
- EXPECT_THROW(Diff d{"<diff><start></start><end>0</end><data>abc</data></diff>"}, std::exception);
- }
-
- {
- Diff d{"<diff><start>0</start><end>0</end><data>abc</data></diff>"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data>abc</data></diff>");
- }
-
- {
- Diff d{"<diff><start>5</start><end>5</end><data>abc</data></diff>"};
- EXPECT_EQ(d.get_xml(), "<diff><start>5</start><end>5</end><data>abc</data></diff>");
- }
-
- {
- Diff d{"<diff><start>5</start><end>50</end><data>abc</data></diff>"};
- EXPECT_EQ(d.get_xml(), "<diff><start>5</start><end>50</end><data>abc</data></diff>");
- }
-
- // constructor via ptree
- {
- pt::ptree ptree;
- EXPECT_THROW(Diff d{ptree}, std::exception);
-
- ptree.put("diff.start", 0);
- ptree.put("diff.end", 0);
- ptree.put("diff.data", "abc");
- Diff d{ptree};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data>abc</data></diff>");
- }
-
- // constructor via versions
- {
- Diff d{"", ""};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data/></diff>");
- }
- {
- Diff d{"a", "a"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data/></diff>");
- }
- {
- Diff d{"a", "b"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>1</end><data>b</data></diff>");
- }
- {
- Diff d{"0a1", "0b1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>2</end><data>b</data></diff>");
- }
- {
- Diff d{"0abc1", "00b01"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>4</end><data>0b0</data></diff>");
- }
- {
- Diff d{"0ab1", "00b01"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>3</end><data>0b0</data></diff>");
- }
- {
- Diff d{"0abc1", "00b1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>4</end><data>0b</data></diff>");
- }
- {
- Diff d{"0abc1", ""};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>5</end><data/></diff>");
- }
- {
- Diff d{"bc1", "0abc1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data>0a</data></diff>");
- }
- {
- Diff d{"0abc1", "0ab"};
- EXPECT_EQ(d.get_xml(), "<diff><start>3</start><end>5</end><data/></diff>");
- }
- {
- Diff d{"0abc1", "0abc123"};
- EXPECT_EQ(d.get_xml(), "<diff><start>5</start><end>5</end><data>23</data></diff>");
- }
- {
- Diff d{"0abc1", "010abc1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>0</end><data>01</data></diff>");
- }
- {
- Diff d{"0abc1", "0ac1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>2</start><end>3</end><data/></diff>");
- }
- {
- Diff d{"0abc1", "0abxc1"};
- EXPECT_EQ(d.get_xml(), "<diff><start>3</start><end>3</end><data>x</data></diff>");
- }
- {
- Diff d{"abc", "c"};
- EXPECT_EQ(d.get_xml(), "<diff><start>0</start><end>2</end><data/></diff>");
- }
- {
- Diff d{"aaaa", "aa"};
- EXPECT_EQ(d.get_xml(), "<diff><start>2</start><end>4</end><data/></diff>");
- }
- {
- Diff d{"baaaa", "baa"};
- EXPECT_EQ(d.get_xml(), "<diff><start>3</start><end>5</end><data/></diff>");
- }
- {
- Diff d{"baaaab", "baab"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>3</end><data/></diff>");
- }
- {
- Diff d{"baaaab", "baaaaaaab"};
- EXPECT_EQ(d.get_xml(), "<diff><start>1</start><end>1</end><data>aaa</data></diff>");
- }
-}
-
-TEST_F(DiffTest, empty)
-{
- {
- Diff d;
- EXPECT_TRUE(d.empty());
- }
-
- {
- Diff d{"<diff><start>1</start><end>3</end><data/></diff>"};
- EXPECT_FALSE(d.empty());
- }
-
- {
- Diff d{"<diff><start>1</start><end>1</end><data/></diff>"};
- EXPECT_TRUE(d.empty());
- }
-
- {
- Diff d{"<diff><start>1</start><end>1</end><data>abc</data></diff>"};
- EXPECT_FALSE(d.empty());
- }
-
- {
- Diff d{"<diff><start>0</start><end>0</end><data/></diff>"};
- EXPECT_TRUE(d.empty());
- }
-}
-
-TEST_F(DiffTest, diff_create)
-{
- const char* result {diff_create("0abc1", "0ab")};
-
- EXPECT_EQ(std::string(result), "<diff><start>3</start><end>5</end><data/></diff>");
- free((void*)result); // this will be done by javascript side in real scenario
-}
-
-TEST_F(DiffTest, diff_apply)
-{
- const char* result {diff_apply("0abc1", "<diff><start>3</start><end>5</end><data/></diff>")};
-
- EXPECT_EQ(std::string(result), "0ab");
- free((void*)result); // this will be done by javascript side in real scenario
-}
-
diff --git a/tests/test-qrcode.cpp b/tests/test-qrcode.cpp
deleted file mode 100644
index 96cfdb0..0000000
--- a/tests/test-qrcode.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-#include <gtest/gtest.h>
-
-#include <filesystem>
-#include <memory>
-#include <string>
-#include <system_error>
-
-#include "libreichwein/file.h"
-
-#include "qrcode.h"
-
-namespace fs = std::filesystem;
-
-class QRCodeTest: public ::testing::Test
-{
-protected:
- QRCodeTest(){
- }
-
- ~QRCodeTest() override{
- }
-
- void SetUp() override
- {
- QRCode::init();
- }
-
- void TearDown() override
- {
- }
-
-};
-
-TEST_F(QRCodeTest, empty)
-{
- unsigned char empty_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
- 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xec, 0x26, 0x09, 0x00, 0x00, 0x00,
- 0xa7, 0x49, 0x44, 0x41, 0x54, 0x28, 0xcf, 0x7d, 0x92, 0x4b, 0x12, 0xc3,
- 0x30, 0x08, 0x43, 0x79, 0x99, 0xde, 0xff, 0xca, 0xea, 0x82, 0x51, 0xf9,
- 0xc4, 0xae, 0x17, 0x89, 0x01, 0x03, 0x02, 0x89, 0x18, 0x47, 0x8a, 0x00,
- 0x29, 0x2d, 0xe8, 0xb1, 0x4f, 0x86, 0x7b, 0x48, 0x02, 0x7b, 0x57, 0xcc,
- 0xa6, 0xd4, 0x43, 0xd3, 0x96, 0x22, 0x9e, 0x38, 0x9e, 0x9e, 0xe2, 0xf3,
- 0x9c, 0x1f, 0x15, 0xde, 0x81, 0xf5, 0x5d, 0x43, 0x02, 0x3f, 0x3e, 0xd5,
- 0x1f, 0xf8, 0x36, 0xee, 0x88, 0x08, 0xae, 0x59, 0x37, 0xac, 0x00, 0xfe,
- 0xee, 0x9d, 0x76, 0x6f, 0x48, 0x52, 0xb5, 0xcc, 0x7b, 0xfd, 0xed, 0x1f,
- 0x1b, 0xa8, 0xec, 0x64, 0x6d, 0x51, 0x31, 0xab, 0x15, 0xf2, 0xb2, 0xdc,
- 0x91, 0x4e, 0x24, 0x48, 0x7d, 0xa3, 0x53, 0x03, 0xaf, 0x0d, 0x54, 0xd3,
- 0x9b, 0x6c, 0x16, 0xa1, 0x7b, 0x34, 0x29, 0x82, 0xa9, 0x9e, 0x84, 0x61,
- 0xc6, 0x66, 0xfd, 0xc7, 0x9b, 0x73, 0x93, 0x2d, 0xc0, 0xf4, 0xc3, 0x1f,
- 0x65, 0xf1, 0x1b, 0xd8, 0x30, 0xae, 0xca, 0x9a, 0x83, 0x02, 0x1c, 0x94,
- 0xe5, 0x4d, 0x27, 0x42, 0x57, 0x3e, 0x34, 0xde, 0x74, 0x16, 0xf2, 0x2f,
- 0x2f, 0xd5, 0xa5, 0xd0, 0x5a, 0x61, 0xde, 0x49, 0x00, 0x00, 0x00, 0x00,
- 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
- };
- // Test prepared with:
- //File::setFile("empty.png", QRCode::getQRCode(""));
- //then: xxd -i tests/empty.png >> tests/test-qrcode.cpp
-
- EXPECT_EQ(QRCode::getQRCode(""), std::string(reinterpret_cast<char*>(&empty_png[0]), sizeof(empty_png)));
-}
-
-TEST_F(QRCodeTest, simple)
-{
- unsigned char simple_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
- 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xec, 0x26, 0x09, 0x00, 0x00, 0x00,
- 0xa5, 0x49, 0x44, 0x41, 0x54, 0x28, 0xcf, 0x75, 0x52, 0xd1, 0x0e, 0xc0,
- 0x40, 0x04, 0x6b, 0x17, 0xff, 0xff, 0xcb, 0xf6, 0xe0, 0x4c, 0x39, 0x93,
- 0x6c, 0x09, 0x47, 0x55, 0x01, 0x9a, 0xb9, 0xbb, 0xbb, 0x03, 0xf9, 0xa9,
- 0x99, 0x86, 0x48, 0x80, 0x8c, 0xe4, 0x2c, 0xd5, 0xb7, 0xcf, 0x2d, 0xa4,
- 0xfa, 0xeb, 0x9b, 0x61, 0xb5, 0xd9, 0x1c, 0x00, 0x9e, 0x2d, 0x2d, 0x88,
- 0xcc, 0xb8, 0xdd, 0x18, 0xa4, 0x3b, 0xa9, 0xad, 0x7f, 0x1b, 0xff, 0x29,
- 0xc0, 0xbd, 0x8a, 0x5c, 0xf0, 0x52, 0xc7, 0x2e, 0x90, 0x2a, 0x91, 0x51,
- 0x4b, 0xfa, 0xc9, 0x2e, 0xfc, 0x40, 0x55, 0x6c, 0xb2, 0xe1, 0xf5, 0x4e,
- 0xd3, 0x7f, 0xaa, 0xf2, 0xa6, 0x52, 0x24, 0x48, 0x77, 0xd9, 0xfa, 0x9c,
- 0x7c, 0xae, 0xf7, 0x52, 0xa0, 0xab, 0xaa, 0x71, 0xeb, 0x5b, 0xa9, 0x21,
- 0xfa, 0x50, 0x67, 0x5b, 0xe3, 0x7a, 0xd0, 0x67, 0x8f, 0x0e, 0xe4, 0x59,
- 0x6c, 0xa4, 0x94, 0x96, 0xda, 0x29, 0xca, 0x80, 0xf5, 0x5c, 0x52, 0x53,
- 0x3d, 0x9a, 0xa3, 0xcb, 0x7d, 0xaf, 0x93, 0xf9, 0xa1, 0xd2, 0xb9, 0xea,
- 0xc6, 0x92, 0xf1, 0x7a, 0x0f, 0xaa, 0xee, 0x8c, 0x03, 0x2f, 0x88, 0x71,
- 0xb5, 0xba, 0xf0, 0x88, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
- 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
- };
- // Test prepared with:
- //File::setFile("simple.png", QRCode::getQRCode("abc"));
- //then: xxd -i tests/simple.png >> tests/test-qrcode.cpp
- EXPECT_EQ(QRCode::getQRCode("abc"), std::string(reinterpret_cast<char*>(&simple_png[0]), sizeof(simple_png)));
-}
-
-TEST_F(QRCodeTest, url)
-{
- unsigned char url_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00,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, 0xda,
- 0x5e, 0x99, 0x2b, 0x38, 0xc5, 0x3f, 0x61, 0x6d, 0x0a, 0x81, 0xf0, 0x56,
- 0x4c, 0x4e, 0x7d, 0xe4, 0x7c, 0x24, 0x9f, 0x39, 0x74, 0xe5, 0x86, 0x86,
- 0x87, 0x04, 0x2e, 0x23, 0xd0, 0xdb, 0x20, 0x8a, 0xe6, 0x60, 0x4f, 0x91,
- 0x7c, 0x32, 0xe6, 0x2f, 0xdc, 0x12, 0x79, 0x31, 0x0a, 0x56, 0xe7, 0xb2,
- 0xef, 0x07, 0x98, 0x8f, 0x8d, 0xe0, 0x6c, 0xd4, 0x04, 0xb6, 0xe1, 0xbf,
- 0xc2, 0x98, 0x97, 0x5d, 0x43, 0xaa, 0x5f, 0xdb, 0xca, 0x6f, 0x57, 0xd3,
- 0xee, 0xe4, 0xec, 0x3e, 0x9c, 0x4d, 0x8e, 0x81, 0xc2, 0x2d, 0x5d, 0x56,
- 0x7e, 0x32, 0x44, 0xbc, 0xed, 0x6a, 0x1a, 0x87, 0xf4, 0x2a, 0xe8, 0x6b,
- 0xad, 0x75, 0x51, 0xfa, 0x66, 0xf4, 0x07, 0x01, 0x97, 0x8d, 0x08, 0x90,
- 0x09, 0xb5, 0xef, 0x64, 0xe7, 0xbf, 0x49, 0x62, 0x8e, 0xfa, 0xec, 0xfb,
- 0x26, 0xad, 0x8d, 0xba, 0x3b, 0xf5, 0xf6, 0xf8, 0x22, 0x95, 0xf7, 0x0f,
- 0x4c, 0x20, 0xaf, 0x2d, 0xca, 0xaf, 0x0d, 0xc5, 0x00, 0x00, 0x00, 0x00,
- 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
- };
- // Test prepared with:
- //File::setFile("url.png", QRCode::getQRCode("https://reichwein.it/whiteboard"));
- //then: xxd -i tests/url.png >> tests/test-qrcode.cpp
- EXPECT_EQ(QRCode::getQRCode("https://reichwein.it/whiteboard"), std::string(reinterpret_cast<char*>(&url_png[0]), sizeof(url_png)));
-}
-
-TEST_F(QRCodeTest, deterministic)
-{
- EXPECT_EQ(QRCode::getQRCode("data1"), QRCode::getQRCode("data1"));
-}
-
-TEST_F(QRCodeTest, different_data)
-{
- EXPECT_NE(QRCode::getQRCode("data1"), QRCode::getQRCode("data2"));
-}
diff --git a/tests/test-whiteboard.cpp b/tests/test-webchat.cpp
index 3f70bcf..3f70bcf 100644
--- a/tests/test-whiteboard.cpp
+++ b/tests/test-webchat.cpp