Skip to content

Commit

Permalink
feat(test): add opcode assert for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Dec 13, 2022
1 parent c02b518 commit 0f96a1b
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ set(libcsound_SRCS
OOps/schedule.c
OOps/sndinfUG.c
OOps/str_ops.c
OOps/test_ops.c
OOps/ugens1.c
OOps/ugens2.c
OOps/ugens3.c
Expand Down
10 changes: 5 additions & 5 deletions Engine/csound_orc_optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ static inline int same_type(char *var, char ty)
else return var[0]==ty;
}
*/
static inline int same_type(char *var, char ty)
{
if (var[0]=='g') return var[1]==ty;
else return var[0]==ty;
}
// static inline int same_type(char *var, char ty)
// {
// if (var[0]=='g') return var[1]==ty;
// else return var[0]==ty;
// }

#define PARSER_DEBUG1 (0)
//static TREE* remove_excess_assigns(CSOUND *csound, TREE* root)
Expand Down
2 changes: 2 additions & 0 deletions Engine/entry1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,8 @@ OENTRY opcodlst_1[] = {
(SUBR) strrindex_opcode, (SUBR) strrindex_opcode, NULL },
{ "print_type", S(PRINT_TYPE_OP),0, 1, "", ".",
(SUBR) print_type_opcode, NULL, NULL },
{ "assert", S(ASSERT_OP),0, 1, "", "i",
(SUBR) assert_opcode, NULL, NULL },
#ifdef HAVE_CURL
{ "strfromurl", S(STRCPY_OP), 0, 1, "S", "S", (SUBR) str_from_url },
#endif
Expand Down
2 changes: 2 additions & 0 deletions H/entry1.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "midiinterop.h"
#include "linevent.h"
#include "str_ops.h"
#include "test_ops.h"
#include "bus.h"
#include "pstream.h"
#include "remote.h"
Expand Down Expand Up @@ -502,4 +503,5 @@ int32_t coef2parm(CSOUND *csound, void *p);
int32_t resonbnk_init(CSOUND *csound, void *p);
int32_t resonbnk(CSOUND *csound, void *p);
int32_t schedule_array(CSOUND *csound, void *p);
int32_t assert_opcode(CSOUND *csound, ASSERT_OP *p);

40 changes: 40 additions & 0 deletions H/test_ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
test_ops.h:
This file is part of Csound.
The Csound Library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Csound is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Csound; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

#ifndef CSOUND_TEST_OPS_H
#define CSOUND_TEST_OPS_H

#ifdef __cplusplus
extern "C" {
#endif


typedef struct {
OPDS h;
MYFLT *boolean;
} ASSERT_OP;


#ifdef __cplusplus
}
#endif

#endif /* CSOUND_TEST_OPS_H */
33 changes: 33 additions & 0 deletions OOps/test_ops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
test_ops.c:
This file is part of Csound.
The Csound Library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Csound is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Csound; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

#include "csoundCore.h"
#include "test_ops.h"

/* increments csound->perferrcnt for false (0) */
int32_t assert_opcode(CSOUND *csound, ASSERT_OP *p)
{
if (*p->boolean == ((MYFLT) 0.0)) {
csound->perferrcnt += 1;
}

return OK;
}
5 changes: 5 additions & 0 deletions include/csound.h
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,11 @@ extern "C" {
*/
PUBLIC void csoundSetHostData(CSOUND *, void *hostData);

/**
* Returns the total error count of the current performance.
*/
PUBLIC int csoundErrCnt(CSOUND *csound);

/**
* Set a single csound option (flag). Returns CSOUND_SUCCESS on success.
* NB: blank spaces are not allowed
Expand Down
25 changes: 25 additions & 0 deletions tests/c/csound_orc_compile_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ TEST_F (OrcCompileTests, testReuse)
csoundPerform(csound);
}

TEST_F (OrcCompileTests, testAssert)
{
int result;
char* instrument =
"instr 1 \n"
"assert(0) \n"
"assert(0) \n"
"assert(0) \n"
"assert(0) \n"
"assert(0) \n"
"assert(0) \n"
"assert(1) \n"
"endin \n";

result = csoundCompileOrc(csound, instrument);
ASSERT_TRUE(result == 0);
result = csoundReadScore(csound, "i 1 0 0\n");
ASSERT_TRUE(result == 0);
result = csoundStart(csound);
ASSERT_TRUE(result == 0);
csoundPerform(csound);
csoundStop(csound);
ASSERT_EQ (6, csoundErrCnt(csound));
}

TEST_F (OrcCompileTests, testLineNumber)
{
char* instrument =
Expand Down

0 comments on commit 0f96a1b

Please sign in to comment.