mirror of
https://github.com/NixOS/nix.git
synced 2025-12-10 02:51:02 +01:00
C API: add more tests to nix_api_expr
This commit is contained in:
parent
415583a500
commit
51ff547d9a
2 changed files with 97 additions and 11 deletions
61
tests/unit/libexpr/nix_api_value.cc
Normal file
61
tests/unit/libexpr/nix_api_value.cc
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "nix_api_store.h"
|
||||
#include "nix_api_store_internal.h"
|
||||
#include "nix_api_util.h"
|
||||
#include "nix_api_util_internal.h"
|
||||
#include "nix_api_expr.h"
|
||||
#include "nix_api_value.h"
|
||||
|
||||
#include "tests/nix_api_store.hh"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nixC {
|
||||
|
||||
class nix_api_value_test : public nix_api_store_test
|
||||
{
|
||||
public:
|
||||
nix_api_value_test()
|
||||
{
|
||||
state = nix_state_create(nullptr, nullptr, store);
|
||||
value = nix_alloc_value(nullptr, state);
|
||||
}
|
||||
~nix_api_value_test()
|
||||
{
|
||||
nix_gc_decref(nullptr, value);
|
||||
nix_state_free(state);
|
||||
}
|
||||
|
||||
EvalState * state;
|
||||
Value * value;
|
||||
};
|
||||
|
||||
TEST_F(nix_api_value_test, nix_value_set_get_int)
|
||||
{
|
||||
int myInt = 1;
|
||||
nix_set_int(nullptr, value, myInt);
|
||||
|
||||
ASSERT_EQ(myInt, nix_get_int(nullptr, value));
|
||||
}
|
||||
|
||||
TEST_F(nix_api_value_test, nix_value_make_list)
|
||||
{
|
||||
int size = 10;
|
||||
nix_make_list(nullptr, state, value, size);
|
||||
ASSERT_EQ(size, nix_get_list_size(nullptr, value));
|
||||
}
|
||||
|
||||
TEST_F(nix_api_value_test, nix_value_set_get_list)
|
||||
{
|
||||
int size = 10;
|
||||
nix_make_list(nullptr, state, value, size);
|
||||
|
||||
Value * intValue = nix_alloc_value(nullptr, state);
|
||||
nix_set_int(nullptr, intValue, 42);
|
||||
nix_set_list_byidx(nullptr, value, 0, intValue);
|
||||
|
||||
ASSERT_EQ(42, nix_get_int(nullptr, nix_get_list_byidx(nullptr, value, state, 0)));
|
||||
|
||||
// Clean up
|
||||
nix_gc_decref(nullptr, intValue);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue