Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestLXNToIGC.cpp
blob00c871ae9e78cc1adf416050ec3b3f8a57dc023b
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Device/Driver/LX/Convert.hpp"
24 #include "TestUtil.hpp"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
30 static const long MAX_LXN_SIZE = 1024 * 1024;
32 static const char *lxn_path = "test/data/lxn_to_igc/18BF14K1.FIL";
33 static const char *igc_in_path = "test/data/lxn_to_igc/18BF14K1.igc";
34 static const char *igc_out_path = "output/18BF14K1.igc";
36 static bool
37 RunConversion()
39 FILE *lxn_file = fopen(lxn_path, "rb");
40 if (lxn_file == NULL) {
41 fprintf(stderr, "Failed to open file %s\n", lxn_path);
42 return false;
45 FILE *igc_file = fopen(igc_out_path, "wb");
46 if (igc_file == NULL) {
47 fprintf(stderr, "Failed to open file %s\n", igc_out_path);
48 return false;
51 long size;
52 if (fseek(lxn_file, 0, SEEK_END) != 0 || (size = ftell(lxn_file)) <= 0 ||
53 fseek(lxn_file, 0, SEEK_SET) != 0 || size > MAX_LXN_SIZE) {
54 fprintf(stderr, "Failed to seek file %s\n", lxn_path);
55 fclose(lxn_file);
56 fclose(igc_file);
57 return false;
60 void *data = malloc(size);
61 size_t n = fread(data, 1, size, lxn_file);
62 fclose(lxn_file);
63 if (n != (size_t)size) {
64 free(data);
65 fprintf(stderr, "Failed to read from file %s\n", lxn_path);
66 fclose(igc_file);
67 return false;
70 bool success = ok1(LX::ConvertLXNToIGC(data, n, igc_file));
71 fclose(igc_file);
72 free(data);
74 return success;
77 static bool
78 CompareFiles()
80 FILE *igc_in_file = fopen(igc_in_path, "rb");
81 if (igc_in_file == NULL) {
82 fprintf(stderr, "Failed to open file %s\n", igc_in_path);
83 return false;
86 FILE *igc_out_file = fopen(igc_out_path, "rb");
87 if (igc_out_file == NULL) {
88 fprintf(stderr, "Failed to open file %s\n", igc_out_path);
89 fclose(igc_in_file);
90 return false;
93 long in_size;
94 if (fseek(igc_in_file, 0, SEEK_END) != 0 || (in_size = ftell(igc_in_file)) <= 0 ||
95 fseek(igc_in_file, 0, SEEK_SET) != 0 || in_size > MAX_LXN_SIZE) {
96 fprintf(stderr, "Failed to seek file %s\n", igc_in_path);
97 fclose(igc_in_file);
98 fclose(igc_out_file);
99 return false;
102 long out_size;
103 if (fseek(igc_out_file, 0, SEEK_END) != 0 || (out_size = ftell(igc_out_file)) <= 0 ||
104 fseek(igc_out_file, 0, SEEK_SET) != 0 || out_size > MAX_LXN_SIZE) {
105 fprintf(stderr, "Failed to seek file %s\n", igc_out_path);
106 fclose(igc_in_file);
107 fclose(igc_out_file);
108 return false;
111 if (in_size != out_size) {
112 fprintf(stderr, "File size doesn't match\n");
113 fclose(igc_in_file);
114 fclose(igc_out_file);
115 return false;
118 void *in_data = malloc(in_size);
119 size_t in_n = fread(in_data, 1, in_size, igc_in_file);
120 fclose(igc_in_file);
121 if (in_n != (size_t)in_size) {
122 free(in_data);
123 fprintf(stderr, "Failed to read from file %s\n", igc_in_path);
124 fclose(igc_out_file);
125 return false;
128 void *out_data = malloc(out_size);
129 size_t out_n = fread(out_data, 1, out_size, igc_out_file);
130 fclose(igc_out_file);
131 if (out_n != (size_t)in_size) {
132 free(out_data);
133 fprintf(stderr, "Failed to read from file %s\n", igc_out_path);
134 return false;
137 return memcmp(in_data, out_data, in_size) == 0;
140 int main(int argc, char **argv)
142 plan_tests(2);
144 if (!RunConversion())
145 skip(1, 0, "conversion failed");
147 ok1(CompareFiles());
149 return exit_status();