1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

test/libutil: Add OBSERVE_STRING macro

Makes string callback easier to pass, without mistakes.
This commit is contained in:
Robert Hensing 2024-04-08 13:13:02 +02:00
parent 876e70bc9a
commit a512f4eebc
4 changed files with 33 additions and 20 deletions

View file

@ -4,14 +4,10 @@
#include "nix_api_store_internal.h"
#include "tests/nix_api_store.hh"
#include "tests/string_callback.hh"
namespace nixC {
void observe_string_cb(const char * start, unsigned int n, std::string * user_data)
{
*user_data = std::string(start);
}
std::string PATH_SUFFIX = "/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-name";
TEST_F(nix_api_util_context, nix_libstore_init)
@ -23,7 +19,7 @@ TEST_F(nix_api_util_context, nix_libstore_init)
TEST_F(nix_api_store_test, nix_store_get_uri)
{
std::string str;
auto ret = nix_store_get_uri(ctx, store, (void *) observe_string_cb, &str);
auto ret = nix_store_get_uri(ctx, store, OBSERVE_STRING(str));
ASSERT_EQ(NIX_OK, ret);
ASSERT_STREQ("local", str.c_str());
}
@ -56,7 +52,7 @@ TEST_F(nix_api_store_test, DoesNotCrashWhenContextIsNull)
TEST_F(nix_api_store_test, get_version)
{
std::string str;
auto ret = nix_store_get_version(ctx, store, (void *) observe_string_cb, &str);
auto ret = nix_store_get_version(ctx, store, OBSERVE_STRING(str));
ASSERT_EQ(NIX_OK, ret);
ASSERT_STREQ(PACKAGE_VERSION, str.c_str());
}
@ -69,7 +65,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
ASSERT_STREQ("dummy", store->ptr->getUri().c_str());
std::string str;
nix_store_get_version(ctx, store, (void *) observe_string_cb, &str);
nix_store_get_version(ctx, store, OBSERVE_STRING(str));
ASSERT_STREQ("", str.c_str());
nix_store_free(store);