1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 10:11:47 +02:00

C API: add nix_api_expr tests

This commit is contained in:
José Luis Lafuente 2024-01-03 19:10:43 +01:00 committed by José Luis Lafuente
parent 55601963b3
commit ac3a9c6605
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
5 changed files with 139 additions and 24 deletions

View file

@ -2,7 +2,8 @@
#include "nix_api_util_internal.h"
#include "nix_api_store.h"
#include "nix_api_store_internal.h"
#include "tests/nix_api_util.hh"
#include "tests/nix_api_store.hh"
#define STORE_DIR "/nix/store/"
#define HASH_PART "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q"
@ -10,24 +11,6 @@ const char * validPath = STORE_DIR HASH_PART "-x";
namespace nixC {
class nix_api_store_test : public nix_api_util_context
{
public:
void SetUp() override
{
nix_api_util_context::SetUp();
nix_libstore_init(ctx);
store = nix_store_open(ctx, "dummy://", NULL);
};
void TearDown() override
{
nix_store_unref(store);
nix_api_util_context::TearDown();
}
Store * store;
};
TEST_F(nix_api_util_context, nix_libstore_init)
{
auto ret = nix_libstore_init(ctx);
@ -39,7 +22,7 @@ TEST_F(nix_api_store_test, nix_store_get_uri)
char value[256];
auto ret = nix_store_get_uri(ctx, store, value, 256);
ASSERT_EQ(NIX_OK, ret);
ASSERT_STREQ("dummy", value);
ASSERT_STREQ("local", value);
}
TEST_F(nix_api_store_test, InvalidPathFails)
@ -67,4 +50,12 @@ TEST_F(nix_api_store_test, DoesNotCrashWhenContextIsNull)
ASSERT_NO_THROW(nix_store_parse_path(nullptr, store, validPath));
}
TEST_F(nix_api_store_test, get_version)
{
char value[256];
auto ret = nix_store_get_version(ctx, store, value, 256);
ASSERT_EQ(NIX_OK, ret);
ASSERT_STREQ(PACKAGE_VERSION, value);
}
}