Skip to content

Commit 1f1e207

Browse files
committed
Renames
1 parent 88b60a3 commit 1f1e207

File tree

10 files changed

+436
-321
lines changed

10 files changed

+436
-321
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ utility/mapcode
3535
*.swp
3636
*.hprof
3737
*.hprof.index
38+
gmon.out
3839
*~
3940

4041
# -----------------------------------------------------------------------------

mapcodelib/mapcoder.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ static enum MapcodeError parseMapcodeString(MapcodeElements *mapcodeElements, co
21082108
} else if (c < 10) { // digit
21092109
token = TOKENCHR; // digit
21102110
if (mapcodeElements) {
2111-
*cleanPtr++ = cx;
2111+
*cleanPtr++ = (char) toupper(cx);
21122112
}
21132113
} else { // character B-Z
21142114
token = TOKENCHR;
@@ -2168,6 +2168,7 @@ static enum MapcodeError parseMapcodeString(MapcodeElements *mapcodeElements, co
21682168
}
21692169
if (isAbjad) {
21702170
convertFromAbjad(mapcodeElements->properMapcode);
2171+
mapcodeElements->indexOfDot = (int) (strchr(mapcodeElements->properMapcode, '.') - mapcodeElements->properMapcode);
21712172
}
21722173
if (*mapcodeElements->territoryISO) {
21732174
mapcodeElements->territoryCode = getTerritoryCode(mapcodeElements->territoryISO, territory);

unittest/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
To build the unit tests, execute:
44

55
cd ../mapcodelib
6-
gcc -O -c mapcoder.c
6+
gcc -DDEBUG -O -c mapcoder.c
77
cd ../unittest
8-
gcc -O unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
8+
gcc -DDEBUG -O -DDEBUG unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
99

1010
To execute the tests, simply execute:
1111

1212
./unittest
1313

14-
## Using ValGrind to Detect Memory Leaks
14+
## Using `valgrind` to Detect Memory Leaks
1515

1616
Compile and run as follows to use `valgrind` (http://valgrind.org) to detect memory leaks:
1717

@@ -36,6 +36,15 @@ And add the environment variable `ASAN_OPTIONS` to your shell:
3636
detect_invalid_pointer_pairs=99999:detect_container_overflow=true:
3737
detect_odr_violation=2:check_initialization_order=true:strict_init_order=true
3838

39+
## Using `gprof` to Profile the Library
40+
41+
Compile and run as follows to use `gprof` to profile the library:
42+
43+
cd ../mapcodelib
44+
gcc -g -O0 -c mapcoder.c -pg
45+
cd ../unittest
46+
gcc -g -O0 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o -pg
47+
3948
## Using Microsoft Visual C++
4049

4150
If you use **Microsoft Visual C++**, you may need to add the following defines to your preprocessor

unittest/decode_test.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ typedef struct {
2424
const char *mapcode; // expected mapcode, empty if no need to test
2525
} EncodeTestRecord;
2626

27-
static const EncodeTestRecord ENCODE_TEST
28-
[] = {
27+
static const EncodeTestRecord ENCODE_TEST[] = {
2928
{-90.0, 0.0, 2, 3, "ATA ZZ.ZZ"},
3029
{-90.0, 0.0, 2, 3, "ATA HK3N.ZZLZ"},
3130
{36.107682, -5.384925, 0, 0, ""},

unittest/run_all.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo "Run all tests..."
2+
date
3+
echo ""
4+
./run_sanitizer.sh
5+
./run_gprof.sh
6+
./run_valgrind.sh
7+
echo ""
8+
echo "Done"

unittest/run_gprof.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
REPORT=report_gprof.txt
2+
3+
echo "Run gprof profiler..." | tee $REPORT
4+
date | tee -a $REPORT
5+
6+
echo "" | tee -a $REPORT
7+
echo "Run with: -O0" | tee -a $REPORT
8+
cd ../mapcodelib
9+
gcc -g -O0 -c mapcoder.c -pg
10+
cd ../unittest
11+
gcc -g -O0 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o -pg
12+
./unittest
13+
gprof ./unittest | tee -a $REPORT
14+
echo "----------------" | tee -a $REPORT
15+
16+
echo "" | tee -a $REPORT
17+
echo "Run with: -O3" | tee -a $REPORT
18+
cd ../mapcodelib
19+
gcc -g -O3 -c mapcoder.c -pg
20+
cd ../unittest
21+
gcc -g -O3 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o -pg
22+
./unittest
23+
gprof ./unittest | tee -a $REPORT
24+
echo "----------------" | tee -a $REPORT
25+
26+
echo "" | tee -a $REPORT
27+
echo "Report in: $REPORT"

unittest/run_sanitizer.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
REPORT=report_sanitizer.txt
2+
export ASAN_OPTIONS=debug=true:strict_string_checks=1:detect_stack_use_after_return=true:detect_invalid_pointer_pairs=99999:detect_container_overflow=true:detect_odr_violation=2:check_initialization_order=true:strict_init_order=true
3+
4+
echo "Run address sanitizer..." | tee $REPORT
5+
date | tee -a $REPORT
6+
7+
# No optimize
8+
echo "" | tee -a $REPORT
9+
echo "Run with: -O0" | tee -a $REPORT
10+
cd ../mapcodelib
11+
gcc -O0 -DDEBUG -c mapcoder.c
12+
cd ../unittest
13+
gcc -O0 -DDEBUG unittest.c -lm -lpthread -fsanitize=address -o unittest
14+
./unittest | tee -a $REPORT
15+
echo "----------------" | tee -a $REPORT sanitize.txt
16+
17+
# Optimize 1
18+
echo "" | tee -a $REPORT
19+
echo "Run with: -O1" | tee -a $REPORT sanitize.txt
20+
cd ../mapcodelib
21+
gcc -O1 -c mapcoder.c
22+
cd ../unittest
23+
gcc -O1 unittest.c -lm -lpthread -fsanitize=address -o unittest
24+
./unittest | tee -a $REPORT
25+
echo "----------------" | tee -a $REPORT sanitize.txt
26+
27+
# Optimize 2
28+
echo "" | tee -a $REPORT
29+
echo "Run with: -O2" | tee -a $REPORT sanitize.txt
30+
cd ../mapcodelib
31+
gcc -O2 -c mapcoder.c
32+
cd ../unittest
33+
gcc -O2 unittest.c -lm -lpthread -fsanitize=address -o unittest
34+
./unittest | tee -a $REPORT
35+
echo "----------------" | tee -a $REPORT sanitize.txt
36+
37+
# Optimize 3
38+
echo "" | tee -a $REPORT
39+
echo "Run with: -O3" | tee -a $REPORT sanitize.txt
40+
cd ../mapcodelib
41+
gcc -O3 -c mapcoder.c
42+
cd ../unittest
43+
gcc -O3 unittest.c -lm -lpthread -fsanitize=address -o unittest
44+
./unittest | tee -a $REPORT
45+
echo "----------------" | tee -a $REPORT sanitize.txt
46+
47+
echo "" | tee -a $REPORT
48+
echo "Report in: $REPORT"

unittest/run_valgrind.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
REPORT=report_valgrind.txt
2+
3+
echo "Run valgrind" | tee $REPORT
4+
5+
echo "" | tee -a $REPORT
6+
echo "Run with: -O0" | tee -a report_valgrind.txt
7+
cd ../mapcodelib
8+
gcc -g -O0 -DDEBUG -c mapcoder.c
9+
cd ../unittest
10+
gcc -g -O0 -DDEBUG unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
11+
valgrind --leak-check=yes ./unittest tee -a $REPORT
12+
echo "----------------" tee -a $REPORT
13+
14+
echo "" | tee -a $REPORT
15+
echo "Run with: -O3" | tee -a report_valgrind.txt
16+
cd ../mapcodelib
17+
gcc -g -O3 -c mapcoder.c
18+
cd ../unittest
19+
gcc -g -O3 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
20+
valgrind --leak-check=yes ./unittest tee -a $REPORT
21+
echo "----------------" tee -a $REPORT
22+
23+
echo "" tee -a $REPORT
24+
echo "Report in: $REPORT"

unittest/test_territories.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct {
2626
enum Territory parent;
2727
} TestTerritoryInfo;
2828

29-
static const TestTerritoryInfo testTerritories[] = {
29+
static const TestTerritoryInfo TEST_TERRITORIES[] = {
3030
{"AAA", TERRITORY_AAA, 0, 0, TERRITORY_NONE},
3131
{"AB", TERRITORY_CA_AB, 0, 0, TERRITORY_CAN},
3232
{"ABW", TERRITORY_ABW, 0, 0, TERRITORY_NONE},

0 commit comments

Comments
 (0)