Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for gexf.c #67

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OUT
ana
io
qp
gexf
*.gcno
*.gcda
*.gcov
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ release: src/main/graphpass.c
debug: ./src/main/graphpass.c
gcc -g -Wall src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass -fprofile-arcs -ftest-coverage

test: qp ana io run clean
test: qp ana io gexf run clean

qp: $(TEST_INCLUDE)runner_test_qp.c
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_qp.c $(DEPS) $(TEST_INCLUDE)quickrun_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o qp
Expand All @@ -46,16 +46,21 @@ ana: $(TEST_INCLUDE)runner_test_ana.c
io: $(TEST_INCLUDE)runner_test_io.c
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_io.c $(DEPS) $(TEST_INCLUDE)io_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o io

gexf: $(TEST_INCLUDE)runner_test_gexf.c
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_gexf.c $(DEPS) $(TEST_INCLUDE)gexf_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o gexf

run:
- ./ana
./qp
./io
./gexf

.PHONY : clean
clean:
rm -f qp
rm -f ana
rm -f io
rm -f gexf
rm -rf TEST_OUT_FOLDER
rm -rf $(BUILD)
rm -f graphpass
Expand Down
33 changes: 0 additions & 33 deletions src/main/gexf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,6 @@

extern int errno;

/** Escapes invalid xml character (&, <, >, ") in attributes */
ruebot marked this conversation as resolved.
Show resolved Hide resolved
int igraph_i_xml_escape(char* src, char** dest) {
long int destlen=0;
char *s, *d;
for (s=src; *s; s++, destlen++) {
if (*s == '&') destlen += 4;
else if (*s == '<') destlen += 3;
else if (*s == '>') destlen += 3;
else if (*s == '"') destlen += 5;
else if (*s == '\'') destlen += 5;
}
*dest=igraph_Calloc(destlen+1, char);
if (!*dest) IGRAPH_ERROR("Not enough memory", IGRAPH_ENOMEM);
for (s=src, d=*dest; *s; s++, d++) {
switch (*s) {
case '&':
strcpy(d, "&amp;"); d+=4; break;
case '<':
strcpy(d, "&lt;"); d+=3; break;
case '>':
strcpy(d, "&gt;"); d+=3; break;
case '"':
strcpy(d, "&quot;"); d+=5; break;
case '\'':
strcpy(d, "&apos;"); d+=5; break;
default:
*d = *s;
}
}
*d=0;
return 0;
}

/** Writes a GEXF file

GEXF provides great support for visualizations and is therefore used by a number
Expand Down
46 changes: 46 additions & 0 deletions src/tests/gexf_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* GraphPass:
* A utility to filter networks and provide a default visualization output
* for Gephi or SigmaJS.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @file quickrun_test.h
@brief Tests for quickrun.h
*/

#include <unistd.h>
#include "unity.h"
#include "graphpass.h"

void setUp() {
ug_quickrun = true;
ug_save = false;
ug_FILENAME = "cpp2.graphml";
ug_OUTPATH = "TEST_OUT_FOLDER/";
ug_percent = 0.0;
ug_DIRECTORY = "src/resources/";
ug_OUTFILE = "file";
ug_gformat = true;
}

void tearDown(void) {
}

void TEST_WRITE_GEXF() {
load_graph("src/resources/cpp2.graphml");
filter_graph();
TEST_ASSERT_TRUE(access("../TEST_OUT_FOLDER/file.gexf", F_OK ));
TEST_ASSERT_TRUE(access("../TEST_OUT_FOLDER/file.gexf", R_OK ));
}
58 changes: 58 additions & 0 deletions src/tests/runner_test_gexf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* GraphPass:
* A utility to filter networks and provide a default visualization output
* for Gephi or SigmaJS.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#define RUN_TEST(TestFunc, TestLineNum) \
{ \
Unity.CurrentTestName = #TestFunc; \
Unity.CurrentTestLineNumber = TestLineNum; \
Unity.NumberOfTests++; \
if (TEST_PROTECT()) \
{ \
setUp(); \
TestFunc(); \
} \
if (TEST_PROTECT()) \
{ \
tearDown(); \
} \
UnityConcludeTest(); \
}

#include "igraph.h"
#include "unity.h"
#include "unity_internals.h"
#include "graphpass.h"
#include "stdio.h"

extern void setUp(void);
extern void tearDown(void);
extern void TEST_WRITE_GEXF(void);

void resetTest(void);
void resetTest(void)
{
tearDown();
setUp();
}

int main (void) {
ug_TEST = true;
UnityBegin("src/tests/gexf_test.c");
RUN_TEST(TEST_WRITE_GEXF, 33);
return (UNITY_END());
}