Added testing program and scripts for parser
This commit is contained in:
parent
e05e86fe67
commit
d5bb76c53f
@ -2,10 +2,16 @@ EX=reflex2q3
|
|||||||
CC=g++
|
CC=g++
|
||||||
CFLAGS=-std=c++11 -I"includes" -I"/usr/include/eigen3"
|
CFLAGS=-std=c++11 -I"includes" -I"/usr/include/eigen3"
|
||||||
|
|
||||||
all: main
|
all: main test
|
||||||
|
|
||||||
main: planes.o brushdef.o oopless-parser.o
|
main: planes.o brushdef.o oopless-parser.o
|
||||||
$(CC) $^ main.cpp $(CFLAGS) -DV8 -o $(EX) 2>error8.log
|
$(CC) $^ main.cpp $(CFLAGS) -o $(EX) 2>error8.log
|
||||||
|
|
||||||
|
test: planes.o brushdef.o oopless-parser.o test-parser.o
|
||||||
|
$(CC) $^ $(CFLAGS) -o test/test-parser
|
||||||
|
|
||||||
|
test-parser.o: test/test-parser.cpp
|
||||||
|
$(CC) -c $^ $(CFLAGS)
|
||||||
|
|
||||||
oopless-parser.o: includes/oopless-parser.cpp
|
oopless-parser.o: includes/oopless-parser.cpp
|
||||||
$(CC) -c $^ $(CFLAGS)
|
$(CC) -c $^ $(CFLAGS)
|
||||||
|
52
ReflexToQ3/test/case-parser-face-3indices.sh
Normal file
52
ReflexToQ3/test/case-parser-face-3indices.sh
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
# Test if the parser is correctly reading in faces with 3 indices.
|
||||||
|
|
||||||
|
# Map Versions as of : 4:26 PM 4/8/2017
|
||||||
|
# Answers are copied from the map file.
|
||||||
|
# The program is expected to output the same string as the answer.
|
||||||
|
|
||||||
|
# test-parser parameters
|
||||||
|
# 1. which parser to test
|
||||||
|
# 2. map file to use
|
||||||
|
# 3. line number to begin from
|
||||||
|
|
||||||
|
function test () {
|
||||||
|
if [ "$1" == "$2" ]; then
|
||||||
|
echo "test passed"
|
||||||
|
else
|
||||||
|
echo "test failed"
|
||||||
|
echo $2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ansr1=" 0.000000 0.000000 1.000000 1.000000 0.000000 5 2 7 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 6 5 7 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 3 1 0 4 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 0 1 2 5 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 4 0 5 6 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 2 1 3 7 0xffffffff common/materials/metal/aluminum
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 3 4 6 7 0xffffffff common/materials/metal/aluminum"
|
||||||
|
test1=$(./test-parser --face "maps/pocket-infinity.map" 142)
|
||||||
|
test $ansr1 $test1
|
||||||
|
|
||||||
|
ansr2=" 0.000000 0.000000 1.000000 1.000000 0.000000 2 0 4 0xffa5a5a5 common/materials/metal/p_metal3
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 1 3 5 0xffa5a5a5 common/materials/metal/p_metal3
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 0 3 1 4 0xffa5a5a5 common/materials/metal/p_metal3
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 3 0 2 5 0xffa5a5a5 common/materials/metal/p_metal3
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 2 4 1 5 0xffa5a5a5 common/materials/metal/p_metal3"
|
||||||
|
test2=$(./test-parser --face "maps/static-discharge.map" 1739)
|
||||||
|
test $ansr2 $test2
|
||||||
|
|
||||||
|
ansr3=" 0.000000 0.000000 1.000000 1.000000 0.000000 1 0 4 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 3 1 4 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 1 2 5 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 0 1 5 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 4 0 6 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 5 2 6 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 0 5 6 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 1 3 7 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 2 1 7 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 6 2 7 0xff727278 common/materials/stone/stone
|
||||||
|
0.000000 0.000000 1.000000 1.000000 0.000000 3 4 6 7 0xff727278 common/materials/stone/stone"
|
||||||
|
test3=$(./test-parser --face "maps/SkyTemples.map" 19354)
|
||||||
|
test $ansr3 $test3
|
102
ReflexToQ3/test/test-parser.cpp
Normal file
102
ReflexToQ3/test/test-parser.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#include "oopless-parser.hpp"
|
||||||
|
#include "brushdef.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// human read output
|
||||||
|
void print_TFace(const TFace x, int i) {
|
||||||
|
cout << "----------------------------" << endl;
|
||||||
|
cout << "TFace #" << i << endl;
|
||||||
|
cout << "\tOffset X: " << x.m_fXOffset << endl;
|
||||||
|
cout << "\tOffset Y: " << x.m_fYOffset << endl;
|
||||||
|
cout << "\tScale X: " << x.m_fXScale << endl;
|
||||||
|
cout << "\tScale Y: " << x.m_fYScale << endl;
|
||||||
|
cout << "\tRotation: " << x.m_fRotation << endl;
|
||||||
|
for (unsigned int i = 0; i < x.m_Indices.size(); ++i) {
|
||||||
|
cout << x.m_Indices[i] << ", ";
|
||||||
|
}
|
||||||
|
cout << "\n\tMaterial: " << x.m_Material << endl;
|
||||||
|
cout << "----------------------------" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for bash script to compare strings.
|
||||||
|
void print_TFace(const TFace x) {
|
||||||
|
#define FMT_PRECISION 6
|
||||||
|
cout <<"\t\t\t"
|
||||||
|
<< fixed << setprecision(FMT_PRECISION) << x.m_fXOffset << " "
|
||||||
|
<< fixed << setprecision(FMT_PRECISION) << x.m_fYOffset << " "
|
||||||
|
<< fixed << setprecision(FMT_PRECISION) << x.m_fXScale << " "
|
||||||
|
<< fixed << setprecision(FMT_PRECISION) << x.m_fYScale << " "
|
||||||
|
<< fixed << setprecision(FMT_PRECISION) << x.m_fRotation << " ";
|
||||||
|
for (const int index : x.m_Indices) {
|
||||||
|
cout << index << " ";
|
||||||
|
}
|
||||||
|
cout << "0x" << hex << x.hex << " "
|
||||||
|
<< x.m_Material;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// jump to a line in fstream
|
||||||
|
// this is to set the stream position to test individual parsing functions.
|
||||||
|
void gotoline(ifstream &f, unsigned int n) {
|
||||||
|
string t;
|
||||||
|
for (unsigned int i = 0; i < n; ++i) {
|
||||||
|
getline(f, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_parsevertices (const char * const fn, const int ln) {
|
||||||
|
ifstream fin;
|
||||||
|
fin.open(fn);
|
||||||
|
string line;
|
||||||
|
gotoline(fin, ln);
|
||||||
|
vector<Eigen::Vector3f> x = parse_vertices(fin);
|
||||||
|
cout << "size has a size of " << x.size() << endl;
|
||||||
|
// display data retrieved.
|
||||||
|
for (unsigned int i = 0; i < x.size(); ++i) {
|
||||||
|
for (unsigned int j = 0; j < 3; ++j) {
|
||||||
|
cout << x[i][j] << "\t";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
getline(fin, line);
|
||||||
|
cout << "check stream state \n current line: " << endl;
|
||||||
|
cout << line << endl;
|
||||||
|
fin.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// test if faces are parsing correctly
|
||||||
|
void test_parseface(const char * const fn, const int ln) {
|
||||||
|
ifstream fin;
|
||||||
|
fin.open(fn);
|
||||||
|
string line;
|
||||||
|
gotoline(fin, ln);
|
||||||
|
vector<TFace> x = parse_face(fin);
|
||||||
|
// cout << "size has a size of " << x.size() << endl;
|
||||||
|
// display data retrieved.
|
||||||
|
for (unsigned int i = 0; i < x.size(); ++i) {
|
||||||
|
print_TFace(x[i]);
|
||||||
|
}
|
||||||
|
// parse_face will rollback to a position if it comes across a keyword
|
||||||
|
// check the line that fin will retrieve.
|
||||||
|
// getline(fin, line);
|
||||||
|
// cout << "check stream state \n current line: " << endl;
|
||||||
|
// cout << line << endl;
|
||||||
|
fin.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char *argv[]) {
|
||||||
|
// test_parsevertices("empty.map", 10);
|
||||||
|
// test_parseface("empty.map", 19);
|
||||||
|
|
||||||
|
// test_parsevertices("pocket-infinity.map", 134);
|
||||||
|
|
||||||
|
if (string(argv[1]) == "--face" || string(argv[1]) == "-f") {
|
||||||
|
if (argc < 4) {
|
||||||
|
cerr << "expected: 3 arguments to program - given: " << argc << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
test_parseface(argv[2], stoi(argv[3]));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user