From 8f6750af84b2c2d5e84852c785ee8fa0b45d5200 Mon Sep 17 00:00:00 2001 From: Daniel Adler Date: Mon, 4 Mar 2024 15:41:58 +0100 Subject: [PATCH 1/2] C++ tests: update third-party objectbox C lib to use 0.21 --- test/integration/optional/cpp/main.cpp | 2 ++ test/integration/property-clear/cpp/step-1.cpp | 2 ++ test/integration/property-clear/cpp/step-2.cpp | 2 ++ test/integration/removes/cpp/step-1.cpp | 2 ++ test/integration/removes/cpp/step-2.cpp | 2 ++ test/integration/renames/cpp/step-1.cpp | 2 ++ test/integration/renames/cpp/step-2.cpp | 2 ++ test/integration/shared/store-init.h | 7 +++++-- test/integration/sync/cpp/main.cpp | 2 ++ test/integration/typeful/cpp/main.cpp | 2 ++ third_party/objectbox-c/get-objectbox-c.sh | 2 +- 11 files changed, 24 insertions(+), 3 deletions(-) diff --git a/test/integration/optional/cpp/main.cpp b/test/integration/optional/cpp/main.cpp index bc0bc4e5..1b762fe1 100644 --- a/test/integration/optional/cpp/main.cpp +++ b/test/integration/optional/cpp/main.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include #include "c-ptr.obx.h" diff --git a/test/integration/property-clear/cpp/step-1.cpp b/test/integration/property-clear/cpp/step-1.cpp index 9cfa5cfb..f6f0fec8 100644 --- a/test/integration/property-clear/cpp/step-1.cpp +++ b/test/integration/property-clear/cpp/step-1.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/property-clear/cpp/step-2.cpp b/test/integration/property-clear/cpp/step-2.cpp index b30100dc..a653250d 100644 --- a/test/integration/property-clear/cpp/step-2.cpp +++ b/test/integration/property-clear/cpp/step-2.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/removes/cpp/step-1.cpp b/test/integration/removes/cpp/step-1.cpp index e4717058..09577aef 100644 --- a/test/integration/removes/cpp/step-1.cpp +++ b/test/integration/removes/cpp/step-1.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/removes/cpp/step-2.cpp b/test/integration/removes/cpp/step-2.cpp index 9b1dc3d4..ea086864 100644 --- a/test/integration/removes/cpp/step-2.cpp +++ b/test/integration/removes/cpp/step-2.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/renames/cpp/step-1.cpp b/test/integration/renames/cpp/step-1.cpp index 5a65bc15..df81b015 100644 --- a/test/integration/renames/cpp/step-1.cpp +++ b/test/integration/renames/cpp/step-1.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/renames/cpp/step-2.cpp b/test/integration/renames/cpp/step-2.cpp index 54c9b6d0..94331fea 100644 --- a/test/integration/renames/cpp/step-2.cpp +++ b/test/integration/renames/cpp/step-2.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "schema.obx.hpp" diff --git a/test/integration/shared/store-init.h b/test/integration/shared/store-init.h index cf85b297..82844ebd 100644 --- a/test/integration/shared/store-init.h +++ b/test/integration/shared/store-init.h @@ -9,7 +9,10 @@ obx::Store testStore(bool removeBeforeOpening, const char* dbDir = nullptr) { if (!dbDir) throw std::invalid_argument("dbDir environment variable not given"); } if (removeBeforeOpening) obx_remove_db_files(dbDir); - obx::Store::Options options(create_obx_model()); - options.directory(dbDir); + obx::Options options; + options + .model(create_obx_model()) + .directory(dbDir) + ; return obx::Store(options); } diff --git a/test/integration/sync/cpp/main.cpp b/test/integration/sync/cpp/main.cpp index 6b437fcd..cdcf3f71 100644 --- a/test/integration/sync/cpp/main.cpp +++ b/test/integration/sync/cpp/main.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "catch2/catch.hpp" #include "objectbox.hpp" #include "objectbox-model.h" diff --git a/test/integration/typeful/cpp/main.cpp b/test/integration/typeful/cpp/main.cpp index f6c33e97..cf2dbfc2 100644 --- a/test/integration/typeful/cpp/main.cpp +++ b/test/integration/typeful/cpp/main.cpp @@ -1,5 +1,7 @@ #define CATCH_CONFIG_MAIN +#define OBX_CPP_FILE + #include "annotated.obx.hpp" #include "catch2/catch.hpp" #include "objectbox.hpp" diff --git a/third_party/objectbox-c/get-objectbox-c.sh b/third_party/objectbox-c/get-objectbox-c.sh index efe8bfdc..aa57c22e 100755 --- a/third_party/objectbox-c/get-objectbox-c.sh +++ b/third_party/objectbox-c/get-objectbox-c.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -cVersion=0.14.0 +cVersion=0.21.0 scriptDir=$(dirname "${BASH_SOURCE[0]}") From 52887c5b0d85be3a2537369d5c5aaeebd934936c Mon Sep 17 00:00:00 2001 From: Daniel Adler Date: Mon, 4 Mar 2024 16:14:31 +0100 Subject: [PATCH 2/2] C++ cmake/compile tests: support for predefines Mainly needed to define OBX_CPP_FILE for C++ link tests with objectbox core lib --- test/build/c-compiler.go | 8 ++++---- test/cmake/libcheck.go | 7 ++++++- test/cmake/libcheck_test.go | 8 ++++---- test/comparison/c-helper.go | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/build/c-compiler.go b/test/build/c-compiler.go index 62910f87..eb5ef180 100644 --- a/test/build/c-compiler.go +++ b/test/build/c-compiler.go @@ -35,18 +35,18 @@ func CanCompileObjectBoxCCpp(t *testing.T, repoRoot string, cpp, required bool) // check objectbox lib if cpp { - err = cmake.LibraryExists("objectbox", []string{"objectbox.hpp"}, includeDirs, libDirs) + err = cmake.LibraryExists("objectbox", []string{"objectbox.hpp"}, includeDirs, libDirs, []string{"OBX_CPP_FILE"}) } else { - err = cmake.LibraryExists("objectbox", []string{"objectbox.h"}, includeDirs, libDirs) + err = cmake.LibraryExists("objectbox", []string{"objectbox.h"}, includeDirs, libDirs, nil) } assert.NoErr(t, err) // check flatbuffers library availability if cpp { // Note: we don't need flatbuffers library explicitly, it's part of objectbox at the moment. - err = cmake.LibraryExists("", []string{"flatbuffers/flatbuffers.h"}, includeDirs, libDirs) + err = cmake.LibraryExists("", []string{"flatbuffers/flatbuffers.h"}, includeDirs, libDirs, nil) } else { - err = cmake.LibraryExists("flatccrt", []string{"stddef.h", "flatcc/flatcc.h", "flatcc/flatcc_builder.h"}, includeDirs, libDirs) + err = cmake.LibraryExists("flatccrt", []string{"stddef.h", "flatcc/flatcc.h", "flatcc/flatcc_builder.h"}, includeDirs, libDirs, nil) } if required { diff --git a/test/cmake/libcheck.go b/test/cmake/libcheck.go index d905f8e1..ab28be81 100644 --- a/test/cmake/libcheck.go +++ b/test/cmake/libcheck.go @@ -26,7 +26,7 @@ import ( ) // LibraryExists tries to compile a simple program linking to the given library -func LibraryExists(name string, includeFiles, includeDirs, linkDirs []string) error { +func LibraryExists(name string, includeFiles, includeDirs, linkDirs, predefines []string) error { build := Cmake{ Name: "check-" + name, IsCpp: true, @@ -51,6 +51,11 @@ func LibraryExists(name string, includeFiles, includeDirs, linkDirs []string) er { // write main.cpp mainPath := filepath.Join(build.ConfDir, build.Files[0]) var mainSrc string + if len(predefines) > 0 { + for _, predefine := range predefines { + mainSrc = mainSrc + "#define " + predefine + "\n" + } + } if len(includeFiles) > 0 { for _, inc := range includeFiles { mainSrc = mainSrc + "#include <" + inc + ">\n" diff --git a/test/cmake/libcheck_test.go b/test/cmake/libcheck_test.go index f9402609..f9d48fb9 100644 --- a/test/cmake/libcheck_test.go +++ b/test/cmake/libcheck_test.go @@ -32,16 +32,16 @@ func TestLibExists(t *testing.T) { t.SkipNow() } - err := cmake.LibraryExists("nonsense", nil, nil, nil) + err := cmake.LibraryExists("nonsense", nil, nil, nil, nil) assert.Err(t, err) - err = cmake.LibraryExists("", []string{"non-existent-lib/include.h"}, nil, nil) + err = cmake.LibraryExists("", []string{"non-existent-lib/include.h"}, nil, nil, nil) assert.Err(t, err) if runtime.GOOS == "windows" { - err = cmake.LibraryExists("", []string{"array"}, nil, nil) + err = cmake.LibraryExists("", []string{"array"}, nil, nil, nil) } else { - err = cmake.LibraryExists("stdc++", []string{"array"}, nil, nil) + err = cmake.LibraryExists("stdc++", []string{"array"}, nil, nil, nil) } assert.NoErr(t, err) } diff --git a/test/comparison/c-helper.go b/test/comparison/c-helper.go index 4c1368ec..451000a3 100644 --- a/test/comparison/c-helper.go +++ b/test/comparison/c-helper.go @@ -104,6 +104,7 @@ func (h cTestHelper) build(t *testing.T, conf testSpec, dir string, expectedErro { // write main.c/cpp to the conf dir - a simple one, just include all sources var mainSrc = "" if cmak.IsCpp { + mainSrc = mainSrc + "#define OBX_CPP_FILE\n" mainSrc = mainSrc + "#include \"objectbox.hpp\"\n" } else { mainSrc = mainSrc + "#include \"objectbox.h\"\n"