summaryrefslogtreecommitdiffhomepage
path: root/mixlib/testsuite
diff options
context:
space:
mode:
authorjaortega <jaortega>2000-12-02 22:32:48 +0000
committerjaortega <jaortega>2000-12-02 22:32:48 +0000
commitdda8ef14aca2b99d620323b3173e967456c92314 (patch)
tree54b3efaf81638539d3d9feb639aa22b4ffdc5a81 /mixlib/testsuite
parent99cc30339d9cb98b240a6e0ef59c333fe3194018 (diff)
downloadmdk-dda8ef14aca2b99d620323b3173e967456c92314.tar.gz
mdk-dda8ef14aca2b99d620323b3173e967456c92314.tar.bz2
added mix_eval_t, a w-expression evaluator
Diffstat (limited to 'mixlib/testsuite')
-rw-r--r--mixlib/testsuite/.cvsignore1
-rw-r--r--mixlib/testsuite/Makefile.am4
-rw-r--r--mixlib/testsuite/mix_eval_t.c115
3 files changed, 119 insertions, 1 deletions
diff --git a/mixlib/testsuite/.cvsignore b/mixlib/testsuite/.cvsignore
index fa47ca5..c936d6c 100644
--- a/mixlib/testsuite/.cvsignore
+++ b/mixlib/testsuite/.cvsignore
@@ -11,6 +11,7 @@ disk5.dev
disk6.dev
disk7.dev
mixdevtest
+mixevaltest
mixinstest
mixparsertest
mixtypest
diff --git a/mixlib/testsuite/Makefile.am b/mixlib/testsuite/Makefile.am
index 62d5db6..81ef11d 100644
--- a/mixlib/testsuite/Makefile.am
+++ b/mixlib/testsuite/Makefile.am
@@ -11,7 +11,7 @@
INCLUDES = -I..
LDADD = $(top_builddir)/mixlib/libmix.a
-check_PROGRAMS = mixtypest mixinstest mixvminstest mixparsertest mixdevtest
+check_PROGRAMS = mixtypest mixinstest mixvminstest mixparsertest mixdevtest mixevaltest
TESTS = $(check_PROGRAMS)
mixtypest_SOURCES = test.h mix_types_t.c
@@ -19,6 +19,8 @@ mixinstest_SOURCES = test.h mix_ins_t.c
mixvminstest_SOURCES = test.h mix_vm_ins_t.c
mixparsertest_SOURCES = test.h mix_parser_t.c
mixdevtest_SOURCES = test.h mix_device_t.c
+mixevaltest_SOURCES = test.h mix_eval_t.c
+
diff --git a/mixlib/testsuite/mix_eval_t.c b/mixlib/testsuite/mix_eval_t.c
new file mode 100644
index 0000000..e9b53c8
--- /dev/null
+++ b/mixlib/testsuite/mix_eval_t.c
@@ -0,0 +1,115 @@
+/* -*-c-*- -------------- mix_eval_t.c :
+ * Test of mix_eval_t
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: "00/12/02 23:18:39 jose"
+ * ------------------------------------------------------------------
+ * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#include <stdlib.h>
+#include <mix_eval.h>
+/* Define VERBOSE_TEST if you want to get prints of the test */
+/* #define VERBOSE_TEST */
+#include "test.h"
+
+typedef struct test_case_t
+{
+ const gchar *expr;
+ gint value;
+ mix_eval_result_t result;
+} test_case_t;
+
+#define ok_case(exp,val) {exp, val, MIX_EVAL_OK}
+#define err_case(exp,err) {exp, 0, err}
+
+typedef struct sym_val_t
+{
+ const gchar *sym;
+ mix_word_t value;
+} sym_val_t;
+
+#define new_symbol(sym,val) {sym, mix_word_new (val)}
+
+int
+main(int argc, char **argv)
+{
+ size_t k;
+ mix_eval_t *eval;
+ mix_short_t loc = mix_short_new (30);
+ sym_val_t symbols[] = {
+ new_symbol ("s0", 43),
+ new_symbol ("s1", -1234),
+ new_symbol ("s2", 0),
+ new_symbol ("s3", -20),
+ new_symbol (NULL, 0)
+ };
+
+ test_case_t cases[] = {
+ ok_case ("2343", 2343),
+ ok_case ("-890", -890),
+ ok_case ("15+1015", 1030),
+ ok_case ("1-481", -480),
+ ok_case ("2300/10", 230),
+ ok_case ("24*3", 72),
+ ok_case ("2:5", 21),
+ ok_case ("1//3", 357913941),
+ ok_case ("12+*", 42),
+ ok_case ("***", 900),
+ ok_case ("1:3*2-4", 18),
+ ok_case ("-1+5*20/6", 13),
+ ok_case ("-1000(0,2),1", 1),
+ ok_case ("s0-s2*3", 129),
+ ok_case ("s3**", -600),
+ ok_case ("s3(3:5)", 20),
+ ok_case ("-s1", 1234),
+ ok_case ("s1/10+s0", 166),
+ err_case ("foo", MIX_EVAL_UNDEF_SYM),
+ err_case ("11--2", MIX_EVAL_SYNTAX),
+ err_case ("foo*3", MIX_EVAL_UNDEF_SYM),
+ err_case ("32),1", MIX_EVAL_MIS_PAREN),
+ err_case ("2000(88)", MIX_EVAL_INV_FSPEC),
+ ok_case (NULL, 0)
+ };
+
+ INIT_TEST;
+ g_print ("Entering mix_eval test...");
+ eval = mix_eval_new ();
+
+ for (k = 0; symbols[k].sym; ++k)
+ mix_eval_set_symbol (eval, symbols[k].sym, symbols[k].value);
+
+ for (k = 0; cases[k].expr; ++k) {
+ mix_eval_result_t r = cases[k].result, s;
+ g_print ("Evaluating \"%s\" = %d ...",
+ cases[k].expr, cases[k].value);
+
+ s = mix_eval_expression_with_loc (eval, cases[k].expr, loc);
+ g_assert (s == r);
+ if ( s == MIX_EVAL_OK ) {
+ mix_word_print (mix_eval_value (eval), "... ");
+ g_print ("\n");
+ g_assert (mix_eval_value (eval) == mix_word_new(cases[k].value));
+ }
+ }
+ mix_eval_delete (eval);
+
+ return EXIT_SUCCESS;
+}
+
+