Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/igo.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ int igo_init (
/* --- inouts --- */
igo_common* igo_cm
) {
if (igo_cm == NULL) {
return 0;
}

igo_cm->cholmod_cm = malloc(sizeof(cholmod_common));
cholmod_start(igo_cm->cholmod_cm);

Expand Down Expand Up @@ -44,6 +48,9 @@ int igo_finish (
/* --- inouts --- */
igo_common* igo_cm
) {
if (igo_cm == NULL) {
return 1;
}
igo_free_sparse(&(igo_cm->A), igo_cm);
igo_free_dense(&(igo_cm->b), igo_cm);
igo_free_factor(&(igo_cm->L), igo_cm);
Expand Down
2 changes: 2 additions & 0 deletions src/igo.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ typedef struct igo_common_struct {
/* Primary functions */
/* ---------------------------------------------------------- */

/* Returns 0 if given a NULL pointer, 1 otherwise. */
int igo_init (
/* --- inouts --- */
igo_common* igo_cm
) ;

/* Always succeeds and returns 1. Attempting to finish a NULL pointer performs no operation on it instead. */
int igo_finish (
/* --- inouts --- */
igo_common* igo_cm
Expand Down
55 changes: 55 additions & 0 deletions tests/test_igo_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <gtest/gtest.h>

extern "C" {
#include <igo.h>
}

TEST(CommonTests, TestInitTypical) {
igo_common* igo_cm = (igo_common*) malloc(sizeof(igo_common));
int ret = igo_init(igo_cm);
ASSERT_EQ(ret, 1);
ASSERT_NE(igo_cm, (void*)NULL);
// check cholmod initialization
ASSERT_NE(igo_cm->cholmod_cm, (void*)NULL);
ASSERT_EQ(igo_cm->cholmod_cm->status, 0);
// check matrices
ASSERT_NE(igo_cm->A, (void*)NULL);
ASSERT_NE(igo_cm->b, (void*)NULL);
ASSERT_NE(igo_cm->L, (void*)NULL);
ASSERT_NE(igo_cm->x, (void*)NULL);
ASSERT_NE(igo_cm->y, (void*)NULL);
// cleanup
cholmod_free_sparse(&igo_cm->A->A, igo_cm->cholmod_cm);
cholmod_free_dense(&igo_cm->b->B, igo_cm->cholmod_cm);
cholmod_free_factor(&igo_cm->L->L, igo_cm->cholmod_cm);
cholmod_free_dense(&igo_cm->x->B, igo_cm->cholmod_cm);
cholmod_free_dense(&igo_cm->y->B, igo_cm->cholmod_cm);
free(igo_cm->A);
free(igo_cm->b);
free(igo_cm->L);
free(igo_cm->x);
free(igo_cm->y);
cholmod_finish(igo_cm->cholmod_cm);
free(igo_cm);
}

TEST(CommonTests, TestFinishTypical) {
igo_common* igo_cm = (igo_common*) malloc(sizeof(igo_common));
igo_init(igo_cm);
int ret = igo_finish(igo_cm);
ASSERT_EQ(ret, 1);
ASSERT_EQ(igo_cm->cholmod_cm, (void*)NULL);
free(igo_cm);
}

TEST(CommonTests, TestFinishNull) {
igo_common* igo_cm = NULL;
int ret = igo_finish(igo_cm);
ASSERT_EQ(ret, 1);
}

TEST(CommonTests, TestInitNull) {
igo_common* igo_cm = NULL;
int ret = igo_init(igo_cm);
ASSERT_EQ(ret, 0);
}