Skip to content

Commit

Permalink
Move tests to separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Dec 8, 2019
1 parent bebe1ce commit fc21997
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 78 deletions.
4 changes: 2 additions & 2 deletions dev/VisualStudio/gps_nmea_parser_dev.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x64.ActiveCfg = Debug|x64
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x64.Build.0 = Debug|x64
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x64.ActiveCfg = Debug|Win32
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x64.Build.0 = Debug|Win32
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x86.ActiveCfg = Debug|Win32
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Debug|x86.Build.0 = Debug|Win32
{C7C465FB-17B3-4226-BBD5-E79C1B3796C6}.Release|x64.ActiveCfg = Release|x64
Expand Down
2 changes: 1 addition & 1 deletion dev/VisualStudio/gps_nmea_parser_dev.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\examples\test_code.c" />
<ClCompile Include="..\..\GPS_NMEA_Parser\src\gps\gps.c" />
<ClCompile Include="..\..\GPS_NMEA_Parser\src\gps\gps_buff.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
6 changes: 3 additions & 3 deletions dev/VisualStudio/gps_nmea_parser_dev.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<ClCompile Include="..\..\GPS_NMEA_Parser\src\gps\gps.c">
<Filter>Source Files\GPS</Filter>
</ClCompile>
<ClCompile Include="..\..\GPS_NMEA_Parser\src\gps\gps_buff.c">
<Filter>Source Files\GPS</Filter>
</ClCompile>
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\examples\test_code.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
71 changes: 7 additions & 64 deletions dev/VisualStudio/main.c
Original file line number Diff line number Diff line change
@@ -1,75 +1,18 @@
/**
* This example uses direct processing function
* to process dummy NMEA data from GPS receiver
*/
/*
* This example uses direct processing function,
* to process dummy NMEA data from GPS receiver
*/
#include "gps/gps.h"
#include "gps/gps_buff.h"
#include <string.h>
#include <stdio.h>
#include <math.h>

#define RUN_TEST(x) if ((x)) { printf("Test passed on line %u with condition " # x "\r\n", (unsigned)__LINE__); } else { printf("Test FAILED on line %u with condition " # x "\r\n", (unsigned)__LINE__ ); }
#define FLT_IS_EQUAL(x, y) (fabs((double)(x) - (double)(y)) < 0.00001)
#define INT_IS_EQUAL(x, y) ((int)((x) == (y)))

/* GPS handle */
gps_t hgps;

/**
* \brief Dummy data from GPS receiver
*/
const char
gps_rx_data[] = ""
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n"
"$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n"
"$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n"
"$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n"
"";
/* External function */
extern void run_tests();

int
main() {
gps_init(&hgps); /* Init GPS */

/* Process all input data */
gps_process(&hgps, gps_rx_data, strlen(gps_rx_data));

/* Run the test */
RUN_TEST(!INT_IS_EQUAL(hgps.is_valid, 0));
RUN_TEST(INT_IS_EQUAL(hgps.fix, 1));
RUN_TEST(INT_IS_EQUAL(hgps.fix_mode, 3));
RUN_TEST(FLT_IS_EQUAL(hgps.latitude, 39.1226000000));
RUN_TEST(FLT_IS_EQUAL(hgps.longitude, -121.0413666666));
RUN_TEST(FLT_IS_EQUAL(hgps.altitude, 646.4000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.coarse, 360.0000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_p, 1.6000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_h, 1.6000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_v, 1.0000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.speed, 0.0000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.geo_sep, -24.100000000));
RUN_TEST(FLT_IS_EQUAL(hgps.variation, 15.500000000));
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_view, 8));

RUN_TEST(INT_IS_EQUAL(hgps.sats_in_use, 5));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[0], 2));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[1], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[2], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[3], 7));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[4], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[5], 9));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[6], 24));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[7], 26));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[8], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[9], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[10], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[11], 0));

RUN_TEST(INT_IS_EQUAL(hgps.date, 8));
RUN_TEST(INT_IS_EQUAL(hgps.month, 3));
RUN_TEST(INT_IS_EQUAL(hgps.year, 1));
RUN_TEST(INT_IS_EQUAL(hgps.hours, 18));
RUN_TEST(INT_IS_EQUAL(hgps.minutes, 37));
RUN_TEST(INT_IS_EQUAL(hgps.seconds, 30));
run_tests();

return 0;
}
4 changes: 2 additions & 2 deletions examples/example1.c → examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* to process dummy NMEA data from GPS receiver
*/
#include "gps/gps.h"
#include "gps/gps_buff.h"
#include <string.h>
#include <stdio.h>

Expand Down Expand Up @@ -32,7 +31,8 @@ gps_rx_data[] = ""

int
main() {
gps_init(&hgps); /* Init GPS */
/* Init GPS */
gps_init(&hgps);

/* Process all input data */
gps_process(&hgps, gps_rx_data, strlen(gps_rx_data));
Expand Down
15 changes: 9 additions & 6 deletions examples/example_buff.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "stdafx.h"
#include "gps/gps.h"
#include "gps/gps_buff.h"
#include "ringbuff/ringbuff.h"
#include <string.h>

/* GPS handle */
gps_t hgps;

/* GPS buffer */
gps_buff_t hgps_buff;
ringbuff_t hgps_buff;
uint8_t hgps_buff_data[12];

/**
Expand Down Expand Up @@ -37,10 +37,11 @@ int
main() {
uint8_t rx;

gps_init(&hgps); /* Init GPS */
/* Init GPS */
gps_init(&hgps);

/* Create buffer for received data */
gps_buff_init(&hgps_buff, hgps_buff_data, sizeof(hgps_buff_data));
ringbuff_init(&hgps_buff, hgps_buff_data, sizeof(hgps_buff_data));

while (1) {
/* Add new character to buffer */
Expand All @@ -50,10 +51,11 @@ main() {
/* Process all input data */
/* Read from buffer byte-by-byte and call processing function */
if (gps_buff_get_full(&hgps_buff)) { /* Check if anything in buffer now */
while (gps_buff_read(&hgps_buff, &rx, 1)) {
while (gps_buff_read(&hgps_buff, &rx, 1) == 1) {
gps_process(&hgps, &rx, 1); /* Process byte-by-byte */
}
} else {
/* Print all data after successful processing */
printf("Latitude: %f degrees\r\n", hgps.latitude);
printf("Longitude: %f degrees\r\n", hgps.longitude);
printf("Altitude: %f meters\r\n", hgps.altitude);
Expand All @@ -74,6 +76,7 @@ uart_irqhandler(void) {
/* Only write to received buffer and process later */
if (write_ptr < strlen(gps_rx_data)) {
/* Write to buffer only */
gps_buff_write(&hgps_buff, &gps_rx_data[write_ptr++], 1);
gps_buff_write(&hgps_buff, &gps_rx_data[write_ptr], 1);
++write_ptr;
}
}
81 changes: 81 additions & 0 deletions examples/test_code.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* This example uses direct processing function,
* to process dummy NMEA data from GPS receiver
*/
#include "gps/gps.h"
#include <string.h>
#include <stdio.h>
#include <math.h>

#define RUN_TEST(x) do { \
if ((x)) { \
printf("Test passed on line %u with condition " # x "\r\n", (unsigned)__LINE__);\
} else { \
printf("Test FAILED on line %u with condition " # x "\r\n", (unsigned)__LINE__ ); \
} \
} while (0)
#define FLT_IS_EQUAL(x, y) (fabs((double)(x) - (double)(y)) < 0.00001)
#define INT_IS_EQUAL(x, y) ((int)((x) == (y)))

/* GPS handle */
gps_t hgps;

/**
* \brief Dummy data from GPS receiver
*/
const char
gps_rx_data[] = ""
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n"
"$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n"
"$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n"
"$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n"
"";

/**
* \brief Run the test of raw input data
*/
void
run_tests() {
gps_init(&hgps); /* Init GPS */

/* Process all input data */
gps_process(&hgps, gps_rx_data, strlen(gps_rx_data));

/* Run the test */
RUN_TEST(!INT_IS_EQUAL(hgps.is_valid, 0));
RUN_TEST(INT_IS_EQUAL(hgps.fix, 1));
RUN_TEST(INT_IS_EQUAL(hgps.fix_mode, 3));
RUN_TEST(FLT_IS_EQUAL(hgps.latitude, 39.1226000000));
RUN_TEST(FLT_IS_EQUAL(hgps.longitude, -121.0413666666));
RUN_TEST(FLT_IS_EQUAL(hgps.altitude, 646.4000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.coarse, 360.0000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_p, 1.6000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_h, 1.6000000000));
RUN_TEST(INT_IS_EQUAL(hgps.dop_v, 1.0000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.speed, 0.0000000000));
RUN_TEST(FLT_IS_EQUAL(hgps.geo_sep, -24.100000000));
RUN_TEST(FLT_IS_EQUAL(hgps.variation, 15.500000000));
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_view, 8));

RUN_TEST(INT_IS_EQUAL(hgps.sats_in_use, 5));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[0], 2));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[1], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[2], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[3], 7));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[4], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[5], 9));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[6], 24));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[7], 26));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[8], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[9], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[10], 0));
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[11], 0));

RUN_TEST(INT_IS_EQUAL(hgps.date, 8));
RUN_TEST(INT_IS_EQUAL(hgps.month, 3));
RUN_TEST(INT_IS_EQUAL(hgps.year, 1));
RUN_TEST(INT_IS_EQUAL(hgps.hours, 18));
RUN_TEST(INT_IS_EQUAL(hgps.minutes, 37));
RUN_TEST(INT_IS_EQUAL(hgps.seconds, 30));
}

0 comments on commit fc21997

Please sign in to comment.