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"
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";
39 FILE *lxn_file
= fopen(lxn_path
, "rb");
40 if (lxn_file
== NULL
) {
41 fprintf(stderr
, "Failed to open file %s\n", lxn_path
);
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
);
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
);
60 void *data
= malloc(size
);
61 size_t n
= fread(data
, 1, size
, lxn_file
);
63 if (n
!= (size_t)size
) {
65 fprintf(stderr
, "Failed to read from file %s\n", lxn_path
);
70 bool success
= ok1(LX::ConvertLXNToIGC(data
, n
, igc_file
));
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
);
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
);
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
);
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
);
107 fclose(igc_out_file
);
111 if (in_size
!= out_size
) {
112 fprintf(stderr
, "File size doesn't match\n");
114 fclose(igc_out_file
);
118 void *in_data
= malloc(in_size
);
119 size_t in_n
= fread(in_data
, 1, in_size
, igc_in_file
);
121 if (in_n
!= (size_t)in_size
) {
123 fprintf(stderr
, "Failed to read from file %s\n", igc_in_path
);
124 fclose(igc_out_file
);
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
) {
133 fprintf(stderr
, "Failed to read from file %s\n", igc_out_path
);
137 return memcmp(in_data
, out_data
, in_size
) == 0;
140 int main(int argc
, char **argv
)
144 if (!RunConversion())
145 skip(1, 0, "conversion failed");
149 return exit_status();