summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWill Estes <wlestes@users.sourceforge.net>2006-10-20 17:10:50 +0000
committerWill Estes <wlestes@users.sourceforge.net>2006-10-20 17:10:50 +0000
commit3ad7f6b2592ce4404c7f72ac92e90b7bfe090d35 (patch)
treeff04d564fbfab5bd5e3fc4c6cb41b373a491d68f /tests
parent1a8b227f8da682c168299dd426102efbb34912fe (diff)
add unit test for c++ with yywrap
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/descriptions1
-rw-r--r--tests/test-c++-yywrap/.cvsignore6
-rw-r--r--tests/test-c++-yywrap/Makefile.am45
-rw-r--r--tests/test-c++-yywrap/scanner.l70
-rw-r--r--tests/test-c++-yywrap/test.input2
6 files changed, 126 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c9d970d..744761a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,6 +26,7 @@ dist_noinst_SCRIPTS = \
create-test
DIST_SUBDIRS = \
+ test-c++-yywrap \
test-extended \
test-ccl \
test-quotes \
@@ -72,6 +73,7 @@ DIST_SUBDIRS = \
test-table-opts
SUBDIRS = \
+ test-c++-yywrap \
test-extended \
test-ccl \
test-quotes \
diff --git a/tests/descriptions b/tests/descriptions
index 9bf891a..b263bbb 100644
--- a/tests/descriptions
+++ b/tests/descriptions
@@ -44,3 +44,4 @@ string-r - Scan strings, reentrant.
table-opts - Try every table compression option.
top - Test %top directive.
yyextra - Test yyextra.
+c++-yywrap - test yywrap in c++ scanner
diff --git a/tests/test-c++-yywrap/.cvsignore b/tests/test-c++-yywrap/.cvsignore
new file mode 100644
index 0000000..31ef089
--- /dev/null
+++ b/tests/test-c++-yywrap/.cvsignore
@@ -0,0 +1,6 @@
+Makefile
+Makefile.in
+scanner.cpp
+OUTPUT
+.deps
+test-c++-yywrap
diff --git a/tests/test-c++-yywrap/Makefile.am b/tests/test-c++-yywrap/Makefile.am
new file mode 100644
index 0000000..2929f28
--- /dev/null
+++ b/tests/test-c++-yywrap/Makefile.am
@@ -0,0 +1,45 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+
+FLEX = $(top_builddir)/flex
+
+EXTRA_DIST = scanner.l test.input
+CLEANFILES = scanner.cpp scanner.h test-c++-yywrap OUTPUT $(OBJS)
+OBJS = scanner.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir)
+LFLAGS = -+
+#LDFLAGS =
+
+testname = test-c++-yywrap
+
+scanner.cpp: $(srcdir)/scanner.l
+ $(FLEX) $(LFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+ $(CXX) -o $@ $(LDFLAGS) $(OBJS)
+
+test: $(testname)$(EXEEXT)
+ ./$(testname)$(EXEEXT) $(srcdir)/test.input $(srcdir)/test.input $(srcdir)/test.input
+
+.cpp.o:
+ $(CXX) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
diff --git a/tests/test-c++-yywrap/scanner.l b/tests/test-c++-yywrap/scanner.l
new file mode 100644
index 0000000..433ad08
--- /dev/null
+++ b/tests/test-c++-yywrap/scanner.l
@@ -0,0 +1,70 @@
+/*
+ * This file is part of flex.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+%{
+
+#include "config.h"
+#include <fstream>
+
+%}
+
+%option 8bit outfile="scanner.cpp" prefix="test"
+%option nounput nomain
+%option warn c++
+
+
+%%
+
+. { }
+
+%%
+
+#define MAX_FILES 10
+
+char *files[MAX_FILES] = { 0 };
+int filecounter = 0;
+
+int testFlexLexer::yywrap()
+{
+ if (filecounter-- > 0) {
+ std::cout << "NOW WRAPPING TO READ " << files[filecounter] << std::endl;
+ std::ifstream *ifs = new std::ifstream(files[filecounter]);
+ switch_streams(ifs);
+ return 0;
+ }
+ return 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+ for (int i = 1; i < argc && i <= MAX_FILES; i++) {
+ files[i-1] = argv[i];
+ filecounter++;
+ }
+ testFlexLexer* f = new testFlexLexer;
+ f->yywrap();
+ f->yylex();
+ std::cout << "TEST RETURNING OK." << std::endl;
+ return 0;
+}
diff --git a/tests/test-c++-yywrap/test.input b/tests/test-c++-yywrap/test.input
new file mode 100644
index 0000000..7288a40
--- /dev/null
+++ b/tests/test-c++-yywrap/test.input
@@ -0,0 +1,2 @@
+0000 foo 1111 foo 0000 bar
+0000 foo 1111 foo 0000 bar