1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 12:23:56 +01:00

Introduced munit for testing

This commit is contained in:
Anthony Scemama 2020-10-17 01:10:54 +02:00
parent 722d6dd540
commit fe3f30ebba
2 changed files with 57 additions and 79 deletions

View File

@ -24,11 +24,9 @@ C than in Fortran.
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
#include "qmckl.h"
#include <stdio.h>
int main() {
qmckl_exit_code rc; /* return code */
rc = QMCKL_SUCCESS;
#include "qmckl.h"
#include "munit.h"
static MunitResult test_qmckl_context() {
#+END_SRC
* Context
@ -128,14 +126,8 @@ qmckl_context qmckl_context_create() {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
context = qmckl_context_create();
if (context == (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_create\n");
rc = QMCKL_FAILURE;
}
if ( qmckl_context_check(context) != context) {
fprintf(stderr,"qmckl_context_create: Invalid context\n");
rc = QMCKL_FAILURE;
}
munit_assert_long( context, !=, (qmckl_context) 0);
munit_assert_long( qmckl_context_check(context), ==, context);
#+END_SRC
** =qmckl_context_copy=
@ -185,19 +177,9 @@ qmckl_context qmckl_context_copy(const qmckl_context context) {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
new_context = qmckl_context_copy(context);
if (new_context == (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_copy: Allocation failure\n");
rc = QMCKL_FAILURE;
}
if (new_context == context ) {
fprintf(stderr,"qmckl_context_copy: Same pointer\n");
rc = QMCKL_FAILURE;
}
if ( qmckl_context_check(new_context) != new_context) {
fprintf(stderr,"qmckl_context_copy: No access to data\n");
rc = QMCKL_FAILURE;
}
munit_assert_long(new_context, !=, (qmckl_context) 0);
munit_assert_long(new_context, !=, context);
munit_assert_long(qmckl_context_check(new_context), ==, new_context);
#+END_SRC
** =qmckl_context_previous=
@ -231,22 +213,10 @@ qmckl_context qmckl_context_previous(const qmckl_context context) {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
if (qmckl_context_previous(new_context) == (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_previous: Null pointer\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_previous(new_context) != context) {
fprintf(stderr,"qmckl_context_previous: Wrong pointer\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_previous(context) != (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_previous: Expected null pointer (1)\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_previous((qmckl_context) 0) != (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_previous: Expected null pointer (2)\n");
rc = QMCKL_FAILURE;
}
munit_assert_long(qmckl_context_previous(new_context), !=, (qmckl_context) 0);
munit_assert_long(qmckl_context_previous(new_context), ==, context);
munit_assert_long(qmckl_context_previous(context), ==, (qmckl_context) 0);
munit_assert_long(qmckl_context_previous((qmckl_context) 0), ==, (qmckl_context) 0);
#+END_SRC
** =qmckl_context_destroy=
@ -283,30 +253,12 @@ qmckl_exit_code qmckl_context_destroy(qmckl_context context) {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
if (qmckl_context_check(new_context) != new_context) {
fprintf(stderr,"qmckl_context_destroy: new_context is invalid\n");
rc = QMCKL_FAILURE;
}
if (new_context == (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_destroy: new_context is NULL\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_destroy(new_context) == QMCKL_FAILURE) {
fprintf(stderr,"qmckl_context_destroy: Unable to destroy the new_context\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_check(new_context) == new_context) {
fprintf(stderr,"qmckl_context_destroy: new_context is valid\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_check(new_context) != (qmckl_context) 0) {
fprintf(stderr,"qmckl_context_destroy: new_context should be NULL\n");
rc = QMCKL_FAILURE;
}
if (qmckl_context_destroy((qmckl_context) 0) == QMCKL_SUCCESS) {
fprintf(stderr,"qmckl_context_destroy: Failure expected with NULL pointer\n");
rc = QMCKL_FAILURE;
}
munit_assert_long(qmckl_context_check(new_context), ==, new_context);
munit_assert_long(new_context, !=, (qmckl_context) 0);
munit_assert_int(qmckl_context_destroy(new_context), ==, QMCKL_SUCCESS);
munit_assert_long(qmckl_context_check(new_context), !=, new_context);
munit_assert_long(qmckl_context_check(new_context), ==, (qmckl_context) 0);
munit_assert_long(qmckl_context_destroy((qmckl_context) 0), ==, QMCKL_FAILURE);
#+END_SRC
@ -441,7 +393,22 @@ int qmckl_context_get_range(const qmckl_context context) {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_context.c
return rc;
}
return MUNIT_OK;
}
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
static MunitTest test_suite_tests[] =
{
{ (char*) "qmckl_context", test_qmckl_context, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite =
{
(char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
}
#+END_SRC

View File

@ -25,11 +25,9 @@ optimized libraries to fine-tune the memory allocation.
*** Test
#+BEGIN_SRC C :tangle test_qmckl_memory.c
#include "qmckl_memory.h"
#include <stdio.h>
int main() {
qmckl_exit_code rc; /* return code */
rc = QMCKL_SUCCESS;
#include "qmckl.h"
#include "munit.h"
static MunitResult test_qmckl_memory() {
#+END_SRC
** =qmckl_malloc=
@ -54,11 +52,9 @@ void* qmckl_malloc(long long int size) {
a[0] = 1;
a[1] = 2;
a[2] = 3;
if ( a[0] != 1 || a[1] != 2 || a[2] != 3 ) {
fprintf(stderr,"qmckl_malloc: Invalid data\n");
rc = QMCKL_FAILURE;
}
munit_assert_int(a[0], ==, 1);
munit_assert_int(a[1], ==, 2);
munit_assert_int(a[2], ==, 3);
#+END_SRC
** =qmckl_free=
@ -89,6 +85,21 @@ void qmckl_free(void *ptr) {
*** Test
#+BEGIN_SRC C :tangle test_qmckl_memory.c
return rc;
return MUNIT_OK;
}
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
static MunitTest test_suite_tests[] =
{
{ (char*) "qmckl_memory", test_qmckl_memory, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite =
{
(char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
}
#+END_SRC