1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <stdio.h>
#include <string.h>
#include "CUnit/Basic.h"
#include "csound.h"
int init_suite1(void)
{
return 0;
}
int clean_suite1(void)
{
return 0;
}
void test_create_buffer(void)
{
csoundSetGlobalEnv("OPCODE6DIR64", "../../");
CSOUND *csound = csoundCreate(0);
int argc = 2;
const char *argv[] = {"csound", "-v"};
csoundCreateMessageBuffer(csound, 0);
csoundCompile(csound, argc, argv);
int cnt = csoundGetMessageCnt(csound);
CU_ASSERT(cnt > 0);
const char * msg = csoundGetFirstMessage(csound);
CU_ASSERT_PTR_NOT_NULL(msg);
int newcnt = csoundGetMessageCnt(csound);
CU_ASSERT_EQUAL(cnt, newcnt);
csoundPopFirstMessage(csound);
newcnt = csoundGetMessageCnt(csound);
CU_ASSERT_EQUAL(cnt - 1, newcnt);
csoundCleanup(csound);
csoundDestroyMessageBuffer(csound);
csoundDestroy(csound);
}
void test_buffer_run(void)
{
csoundSetGlobalEnv("OPCODE6DIR64", "../../");
CSOUND *csound = csoundCreate(0);
csoundCreateMessageBuffer(csound, 0);
csoundCompileOrc(csound, "instr 1\n"
"asig oscil 0.1, 440\n"
"out asig\n"
"endin\n");
csoundReadScore(csound, "i 1 0 0.1\n");
csoundStart(csound);
csoundPerform(csound);
while (csoundGetMessageCnt(csound)) {
const char * msg = csoundGetFirstMessage(csound);
CU_ASSERT_PTR_NOT_NULL(msg);
printf("CSOUND MESSAGE: %s", msg);
csoundPopFirstMessage(csound);
}
csoundCleanup(csound);
csoundDestroyMessageBuffer(csound);
csoundDestroy(csound);
}
int main()
{
CU_pSuite pSuite = NULL;
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite("Message Buffer Tests", init_suite1, clean_suite1);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}
/* add the tests to the suite */
if ((NULL == CU_add_test(pSuite, "Create Message Buffer", test_create_buffer))
|| (NULL == CU_add_test(pSuite, "Test run", test_buffer_run))
)
{
CU_cleanup_registry();
return CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}
|