From 70ebe533358e83d5e7080957d29a683d87f4ba79 Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Thu, 5 Sep 2024 14:42:37 +0100 Subject: [PATCH] Added unit test for account deserialisation --- .../Connector.xcodeproj/project.pbxproj | 4 +++ .../ConnectorTests/AccountTests.cpp | 33 +++++++++++++++++++ SpeckleLib/SpeckleLibDoctest/Guid32Tests.cpp | 15 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 SpeckleConnector/ConnectorTests/AccountTests.cpp create mode 100644 SpeckleLib/SpeckleLibDoctest/Guid32Tests.cpp diff --git a/SpeckleConnector/Connector.xcodeproj/project.pbxproj b/SpeckleConnector/Connector.xcodeproj/project.pbxproj index f66fa1a..e427d29 100644 --- a/SpeckleConnector/Connector.xcodeproj/project.pbxproj +++ b/SpeckleConnector/Connector.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 21B67CF12C78D38000FD64FC /* GoAway.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CF02C78D38000FD64FC /* GoAway.cpp */; }; 21B67CF72C78D4DE00FD64FC /* GetComplexType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CF52C78D4DD00FD64FC /* GetComplexType.cpp */; }; 21D0BD602C89BFEA0077E104 /* SendBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BD5B2C89BFEA0077E104 /* SendBridge.cpp */; }; + 21D0BD672C89D7410077E104 /* AccountTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BD642C89D7400077E104 /* AccountTests.cpp */; }; 21D1E9AD2BF14AF200957EAA /* BIMData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9152BF14AEC00957EAA /* BIMData.framework */; }; 21D1E9AE2BF14AF200957EAA /* TeamworkPortalServerClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9162BF14AEC00957EAA /* TeamworkPortalServerClient.framework */; }; 21D1E9AF2BF14AF200957EAA /* GDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9172BF14AEC00957EAA /* GDL.framework */; }; @@ -307,6 +308,7 @@ 21B67CF62C78D4DE00FD64FC /* GetComplexType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetComplexType.h; sourceTree = ""; }; 21D0BD5B2C89BFEA0077E104 /* SendBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SendBridge.cpp; sourceTree = ""; }; 21D0BD5C2C89BFEA0077E104 /* SendBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SendBridge.h; sourceTree = ""; }; + 21D0BD642C89D7400077E104 /* AccountTests.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = AccountTests.cpp; sourceTree = ""; }; 21D1E9152BF14AEC00957EAA /* BIMData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BIMData.framework; path = "../Archicad 27/Support/Frameworks/BIMData.framework"; sourceTree = ""; }; 21D1E9162BF14AEC00957EAA /* TeamworkPortalServerClient.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TeamworkPortalServerClient.framework; path = "../Archicad 27/Support/Frameworks/TeamworkPortalServerClient.framework"; sourceTree = ""; }; 21D1E9172BF14AEC00957EAA /* GDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GDL.framework; path = "../Archicad 27/Support/Frameworks/GDL.framework"; sourceTree = ""; }; @@ -874,6 +876,7 @@ 219F30412C769282009834E9 /* ConnectorTests */ = { isa = PBXGroup; children = ( + 21D0BD642C89D7400077E104 /* AccountTests.cpp */, 219F30402C769282009834E9 /* ConfigTests.cpp */, 219F30432C7693B6009834E9 /* Connector-AC27-Debug.xctestplan */, ); @@ -1325,6 +1328,7 @@ buildActionMask = 2147483647; files = ( 219F30422C769283009834E9 /* ConfigTests.cpp in Sources */, + 21D0BD672C89D7410077E104 /* AccountTests.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SpeckleConnector/ConnectorTests/AccountTests.cpp b/SpeckleConnector/ConnectorTests/AccountTests.cpp new file mode 100644 index 0000000..cb224fc --- /dev/null +++ b/SpeckleConnector/ConnectorTests/AccountTests.cpp @@ -0,0 +1,33 @@ +#include "ActiveLibDoctest/TestingPlatforms.h" + +#include "Active/Serialise/JSON/JSONTransport.h" +#include "Active/Serialise/Package/PackageWrap.h" +#include "Active/Utility/BufferIn.h" +#include "Speckle/Record/Credentials/Account.h" + +using namespace active::serialise; +using namespace active::serialise::json; +using namespace active::serialise::json; +using namespace speckle::record::cred; +using namespace speckle::utility; + +namespace { + + const char* accountJSON = "{\"id\":\"194B6E32061EB588B31D8CBC167DAAD8\",\"token\":\"547e30bcd0f0e377fe422019f388295e37c583a99f\",\"refreshToken\":\"7d23031b44856e768b5951161c9bc8378f663eefce\",\"isDefault\":false,\"isOnline\":false,\"serverInfo\":{\"name\":\"My new Speckle Server\",\"company\":\"Unknown Company\",\"version\":\"2.20.2-branch.testing.138676-e8c8291\",\"adminContact\":\"n/a\",\"description\":\"This a community deployment of a Speckle Server.\",\"frontend2\":true,\"url\":\"https://testing.speckle.dev\",\"migration\":null},\"userInfo\":{\"id\":\"e66694013f\",\"name\":\"oguzhan@speckle.systems\",\"email\":\"oguzhan@speckle.systems\",\"company\":null,\"avatar\":null,\"streams\":{\"totalCount\":2},\"commits\":{\"totalCount\":5}}}"; + +} + + +TEST_SUITE(TESTQ(AccountTests)) TEST_SUITE_OPEN + + //Test to receive account serialised as JSON from SQLite dbase + TEST_CASE(TESTQ(testAccountReceive)) { + Account account; + try { + JSONTransport().receive(PackageWrap{account}, Identity{}, String{accountJSON}); + } catch(...) { + FAIL_CHECK(TEST_MESSAGE(Account deserialisation failed)); + } + } + +TEST_SUITE_CLOSE diff --git a/SpeckleLib/SpeckleLibDoctest/Guid32Tests.cpp b/SpeckleLib/SpeckleLibDoctest/Guid32Tests.cpp new file mode 100644 index 0000000..1267690 --- /dev/null +++ b/SpeckleLib/SpeckleLibDoctest/Guid32Tests.cpp @@ -0,0 +1,15 @@ +#include "ActiveLibDoctest/TestingPlatforms.h" + +#include "Speckle/Utility/Guid32.h" + +using namespace speckle::utility; + +TEST_SUITE(TESTQ(GuidTests)) TEST_SUITE_OPEN + + ///Tests for creating/modifying guids + TEST_CASE(TESTQ(testGuidContent)) { + Guid32 badGuid{String{"abcd"}}; + CHECK_MESSAGE(!badGuid, TEST_MESSAGE(Guid32 created from bad data)); + } + +TEST_SUITE_CLOSE