Skip to content

Commit

Permalink
test/integration/cmake: update project changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-obx committed Aug 15, 2024
1 parent 3702a70 commit 60e49e1
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/integration/cmake/cmake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,31 @@ func TestCMakeProjects(t *testing.T) {
}
}
}
// Test updating for just "cpp-flat" using content from "update-cpp-flat" folder.
if project == "cpp-flat" {
t.Logf("**** Update project cpp-flat (task.fbs and main.cpp) ****")
cmake.CopyDir(wd, filepath.Join("update-cpp-flat", "."), filepath.Join(confDir))
if multiConfigBuild {
configs := []string{"Release", "Debug"}
for _, config := range configs {
if stdOut, stdErr, err := conf.BuildDefaultsWithConfig(config); err != nil {
t.Fatalf("cmake build after update (configuration %s) failed: \n%s\n%s\n%s", config, stdOut, stdErr, err)
} else {
t.Logf("build after update (configuration %s) output:\n%s", config, string(stdOut))
}
}
} else {
if stdOut, stdErr, err := conf.BuildDefaults(); err != nil {
t.Fatalf("cmake build after update failed: \n%s\n%s\n%s", stdOut, stdErr, err)
} else {
t.Logf("build after update output:\n%s", string(stdOut))
}
}
}
}
}
}

}

for _, singleGenerator := range singleGenerators {
Expand All @@ -155,3 +177,6 @@ func TestCMakeProjects(t *testing.T) {
run(multiGenerator, true)
}
}

func TestCMakeProjectModify(t *testing.T) {
}
42 changes: 42 additions & 0 deletions test/integration/cmake/update-cpp-flat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.14)

project(objectbox-generator-cmake-cpp-flat CXX)

include(../common.cmake)

add_executable(objectbox-test main.cpp)
target_link_libraries(objectbox-test objectbox)

set_target_properties(objectbox-test PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
)

# Variants:
# - multiple add_obx_schema calls on same target
# - single add_obx_schema call adding two schemas
# - use OUTPUT_DIR_HEADERS (without OUTPUT_DIR)
if (DO_INSOURCE)
add_obx_schema(
TARGET
objectbox-test
SCHEMA_FILES
task.fbs
monster.fbs
person.fbs
INSOURCE
OUTPUT_DIR_MODEL_JSON model
OUTPUT_DIR_HEADERS
include2
)
target_include_directories(objectbox-test PRIVATE include2)
else()
add_obx_schema(
TARGET
objectbox-test
SCHEMA_FILES
task.fbs
monster.fbs
person.fbs
)
endif()
43 changes: 43 additions & 0 deletions test/integration/cmake/update-cpp-flat/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#define OBX_CPP_FILE


#include "objectbox.hpp"

#include "objectbox-model.h"
#include "task.obx.hpp"
#include "monster.obx.hpp"
#include "person.obx.hpp"

#include <cinttypes>

int main(int argc, char* args[])
{
// create_obx_model() provided by objectbox-model.h
// obx interface contents provided by objectbox.hpp
obx::Store store(create_obx_model());
obx::Box<Task> box(store);

Task my_task{};
my_task.text = "Buy milk";
obx_id id = box.put(my_task); // Create

std::unique_ptr<Task> task = box.get(id); // Read
if (task) {
task->text += " & some bread";
box.put(*task); // Update
}

printf("Your task has ID=%" PRIu64 ", text=%s\n, text2=%s\n",
id,
box.get(id)->text.c_str(),
box.get(id)->text2.c_str());

obx::Box<Person> person_box(store);
Person my_person{};
obx_id person_id = person_box.put(my_person); // Create

printf("Your person has ID=%" PRIu64, person_id);

return 0;
}
5 changes: 5 additions & 0 deletions test/integration/cmake/update-cpp-flat/person.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
table Person {
id: ulong;
name: string;
age: int;
}
7 changes: 7 additions & 0 deletions test/integration/cmake/update-cpp-flat/task.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
table Task {
id: ulong;
text: string;
text2: string;
date_created: ulong;
date_finished: ulong;
}

0 comments on commit 60e49e1

Please sign in to comment.