summaryrefslogtreecommitdiff
path: root/tests/test-c++-yywrap
diff options
context:
space:
mode:
authorwlestes <wlestes>2006-10-20 17:10:50 +0000
committerwlestes <wlestes>2006-10-20 17:10:50 +0000
commitd78f585565418239fc6d7f94cafd577e6fcbcedd (patch)
treed8ba18d1567053a3908123b4f28c51c9bd89d7cf /tests/test-c++-yywrap
parent94d033788b89ebf55bcb4b96fb953f8fd53f5cfe (diff)
downloadflex-d78f585565418239fc6d7f94cafd577e6fcbcedd.tar.gz
add unit test for c++ with yywrap
Diffstat (limited to 'tests/test-c++-yywrap')
-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
4 files changed, 123 insertions, 0 deletions
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