mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Merge pull request #13395 from xokdvium/libstore-tests-leaks
libstore-tests: Don't leak memory in tests
This commit is contained in:
commit
df2d5f276a
2 changed files with 13 additions and 4 deletions
|
@ -34,6 +34,8 @@ public:
|
||||||
Store * store;
|
Store * store;
|
||||||
std::string nixDir;
|
std::string nixDir;
|
||||||
std::string nixStoreDir;
|
std::string nixStoreDir;
|
||||||
|
std::string nixStateDir;
|
||||||
|
std::string nixLogDir;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init_local_store()
|
void init_local_store()
|
||||||
|
@ -53,11 +55,13 @@ protected:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nixStoreDir = nixDir + "/my_nix_store";
|
nixStoreDir = nixDir + "/my_nix_store";
|
||||||
|
nixStateDir = nixDir + "/my_state";
|
||||||
|
nixLogDir = nixDir + "/my_log";
|
||||||
|
|
||||||
// Options documented in `nix help-stores`
|
// Options documented in `nix help-stores`
|
||||||
const char * p1[] = {"store", nixStoreDir.c_str()};
|
const char * p1[] = {"store", nixStoreDir.c_str()};
|
||||||
const char * p2[] = {"state", (new std::string(nixDir + "/my_state"))->c_str()};
|
const char * p2[] = {"state", nixStateDir.c_str()};
|
||||||
const char * p3[] = {"log", (new std::string(nixDir + "/my_log"))->c_str()};
|
const char * p3[] = {"log", nixLogDir.c_str()};
|
||||||
|
|
||||||
const char ** params[] = {p1, p2, p3, nullptr};
|
const char ** params[] = {p1, p2, p3, nullptr};
|
||||||
|
|
||||||
|
|
|
@ -71,17 +71,21 @@ TEST_F(nix_api_store_test, ReturnsValidStorePath)
|
||||||
ASSERT_NE(result, nullptr);
|
ASSERT_NE(result, nullptr);
|
||||||
ASSERT_STREQ("name", result->path.name().data());
|
ASSERT_STREQ("name", result->path.name().data());
|
||||||
ASSERT_STREQ(PATH_SUFFIX.substr(1).c_str(), result->path.to_string().data());
|
ASSERT_STREQ(PATH_SUFFIX.substr(1).c_str(), result->path.to_string().data());
|
||||||
|
nix_store_path_free(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(nix_api_store_test, SetsLastErrCodeToNixOk)
|
TEST_F(nix_api_store_test, SetsLastErrCodeToNixOk)
|
||||||
{
|
{
|
||||||
nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
StorePath * path = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
||||||
ASSERT_EQ(ctx->last_err_code, NIX_OK);
|
ASSERT_EQ(ctx->last_err_code, NIX_OK);
|
||||||
|
nix_store_path_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(nix_api_store_test, DoesNotCrashWhenContextIsNull)
|
TEST_F(nix_api_store_test, DoesNotCrashWhenContextIsNull)
|
||||||
{
|
{
|
||||||
ASSERT_NO_THROW(nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str()));
|
StorePath * path = nullptr;
|
||||||
|
ASSERT_NO_THROW(path = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str()));
|
||||||
|
nix_store_path_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(nix_api_store_test, get_version)
|
TEST_F(nix_api_store_test, get_version)
|
||||||
|
@ -119,6 +123,7 @@ TEST_F(nix_api_store_test, nix_store_is_valid_path_not_in_store)
|
||||||
{
|
{
|
||||||
StorePath * path = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
StorePath * path = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
||||||
ASSERT_EQ(false, nix_store_is_valid_path(ctx, store, path));
|
ASSERT_EQ(false, nix_store_is_valid_path(ctx, store, path));
|
||||||
|
nix_store_path_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(nix_api_store_test, nix_store_real_path)
|
TEST_F(nix_api_store_test, nix_store_real_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue