Skip to content
Snippets Groups Projects
Commit f77226eb authored by florian's avatar florian
Browse files

FIX: Unit tests

parent ca07e4d2
No related branches found
No related tags found
4 merge requests!12F consolidation,!10API: remove UniqueResult, lower-case at, size for ResultSet,!9Draft: API: remove UniqueResult, lower-case at, size for ResultSet,!8ENH: Add retrieval and queries to Extern C interface
Pipeline #11868 failed
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
......@@ -512,8 +512,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
auto *wrapped_result_set =
static_cast<caosdb::transaction::MultiResultSet *>(
result_set->wrapped_result_set);
auto requested_entity = wrapped_result_set->At(index);
entity->wrapped_entity = (&requested_entity);
entity->wrapped_entity =
wrapped_result_set->mutable_at(index);
return 0;
})
......@@ -524,7 +524,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
auto *wrapped_result_set =
static_cast<caosdb::transaction::MultiResultSet *>(
result_set->wrapped_result_set);
int size(wrapped_result_set->Size());
int size(wrapped_result_set->size());
*out = size;
return 0;
})
......
......@@ -30,6 +30,7 @@
#include "gtest/gtest-test-part.h" // for SuiteApiResolver, TestPa...
#include "gtest/gtest_pred_impl.h" // for Test, TestInfo, TEST
#include <memory> // for allocator, unique_ptr
#include <stdexcept> // for out_of_range
#include <string> // for string, basic_string
#include <utility> // for move
#include <vector> // for vector
......@@ -37,27 +38,30 @@
namespace caosdb::transaction {
using caosdb::configuration::InsecureConnectionConfiguration;
using caosdb::connection::Connection;
using caosdb::exceptions::ConnectionError;
using caosdb::entity::Entity;
using caosdb::exceptions::ConnectionError;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::entity::v1alpha1::RetrieveResponse;
TEST(test_transaction, test_multi_result_set) {
std::vector<std::unique_ptr<Entity>> entities;
for(int i = 0; i < 5; i++) {
for (int i = 0; i < 5; i++) {
entities.push_back(std::make_unique<Entity>());
entities[i].SetName("E" + std::to_string(i));
entities[i]->SetName("E" + std::to_string(i));
}
MultiResultSet result_set(std::move(entities));
EXPECT_EQ(result_set.size(), 5);
EXPECT_EQ(result_set.mutable_at(3)->GetName(), "E2");
EXPECT_EQ(result_set.at(4)->GetName(), "E3");
EXPECT_EQ(result_set.at(4)->GetName(), "E3");
EXPECT_THROW(result_set.at(15), std::out_of_range);
EXPECT_EQ(result_set.mutable_at(2)->GetName(), "E2");
EXPECT_EQ(result_set.at(3).GetName(), "E3");
EXPECT_EQ(result_set.at(3).GetName(), "E3");
// discarding a [[nodiscard]] return value here (ok, we're only
// interested in the error anyway), so ignore when linting
EXPECT_THROW(result_set.at(15), std::out_of_range); // NOLINT
int counter = 0;
for(const auto &entity : result_set) {
for (const auto &entity : result_set) {
EXPECT_EQ(entity.GetName(), "E" + std::to_string(counter++));
}
EXPECT_EQ(counter, 5);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment