Debian Codegraph @

test/test.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <spctag.h>
7
8 int main( int argc, char **argv )
9 {
10 FILE *spc_file; // Our SPC file
11 char* test_str = "abcdefghijklmnopqrstuvwxyzabcdef-azerty";
12 char* test_date = "12/31/1999";
13 char *test_num = "999";
14 char song_title[SPCTAG_SONGTITLE_LENGTH+1];
15 char game_title[SPCTAG_GAMETITLE_LENGTH+1];
16 char dumper_name[SPCTAG_DUMPERNAME_LENGTH+1];
17 char comments[SPCTAG_COMMENTS_LENGTH+1];
18 char dump_date[SPCTAG_DUMPDATE_TXT_LENGTH+1];
19 char length[SPCTAG_LENGTH_LENGTH+1];
20 char fade_length[SPCTAG_FADELENGTH_BIN_LENGTH+1];
21 char artist[SPCTAG_ARTIST_LENGTH+1];
22 char channels[9];
23 char emulator[20];
24
25 // Exit if no filename is specify
26 if ( argc < 2 ) {
27 fprintf( stderr, "Usage : %s filname\n", argv[0]);
28 exit( 1 );
29 }
30
31 // Open file or exit
32 if ( ( spc_file = fopen( argv[1], "r+b" ) ) == NULL ) {
33 fprintf( stderr, "Unable to open file '%s'!\n", argv[1] );
34 exit( 2 );
35 }
36
37 spctag_init( spc_file );
38
39 printf( "Version : %s\n", LIBSPCTAG_VERSION_STR );
40
41 if ( spctag_txt_tag )
42 printf( "Tags format: Text\n\n" );
43 else
44 printf( "Tags format: Binary\n\n" );
45
46 printf( "--- Test reading tags ---\n");
47
48 strcpy( song_title, spctag_get_songtitle() );
49 strcpy( game_title, spctag_get_gametitle() );
50 strcpy( dumper_name, spctag_get_dumpername() );
51 strcpy( comments, spctag_get_comments() );
52 strcpy( dump_date, spctag_get_dumpdate() );
53 strcpy( length, spctag_get_length() );
54 strcpy( fade_length, spctag_get_fadelength() );
55 strcpy( artist, spctag_get_artist() );
56 strcpy( channels, spctag_get_defaultchannels() );
57 strcpy( emulator, spctag_get_emulator() );
58
59 printf("Song title : %s\n", song_title );
60 printf("Game title : %s\n", game_title );
61 printf("Dumper name : %s\n", dumper_name );
62 printf("Comments : %s\n", comments );
63 printf("Dump date : %s\n", dump_date );
64 printf("Length : %s\n", length );
65 printf("Fade length : %s\n", fade_length );
66 printf("Artist : %s\n", artist );
67 printf("Default channels : %s\n", channels );
68 printf("Emulator : %s\n", emulator );
69
70 printf( "\n--- Test writing tags ---\n");
71
72 spctag_set_songtitle( test_str );
73 spctag_set_gametitle( test_str );
74 spctag_set_dumpername( test_str );
75 spctag_set_comments( test_str );
76 spctag_set_dumpdate( test_date );
77 spctag_set_length( test_num );
78 spctag_set_fadelength( test_num );
79 spctag_set_artist( test_str );
80 spctag_set_defaultchannels( "01010101" );
81 spctag_set_emulator( "Snes9x" );
82
83 spctag_save( spc_file );
84
85 printf("Song title : %s\n", spctag_get_songtitle() );
86 printf("Game title : %s\n", spctag_get_gametitle() );
87 printf("Dumper name : %s\n", spctag_get_dumpername() );
88 printf("Comments : %s\n", spctag_get_comments() );
89 printf("Dump date : %s\n", spctag_get_dumpdate() );
90 printf("Length : %s\n", spctag_get_length() );
91 printf("Fade length : %s\n", spctag_get_fadelength() );
92 printf("Artist : %s\n", spctag_get_artist() );
93 printf("Default channels : %s\n", spctag_get_defaultchannels() );
94 printf("Emulator : %s\n", spctag_get_emulator() );
95
96 printf( "\n--- Restor original tags ---\n");
97
98 spctag_set_songtitle( song_title );
99 spctag_set_gametitle( game_title );
100 spctag_set_dumpername( dumper_name );
101 spctag_set_comments( comments );
102 spctag_set_dumpdate( dump_date );
103 spctag_set_length( length );
104 spctag_set_fadelength( fade_length );
105 spctag_set_artist( artist );
106 spctag_set_defaultchannels( channels );
107 spctag_set_emulator( emulator );
108
109 spctag_save( spc_file );
110
111 printf("Song title : %s\n", spctag_get_songtitle() );
112 printf("Game title : %s\n", spctag_get_gametitle() );
113 printf("Dumper name : %s\n", spctag_get_dumpername() );
114 printf("Comments : %s\n", spctag_get_comments() );
115 printf("Dump date : %s\n", spctag_get_dumpdate() );
116 printf("Length : %s\n", spctag_get_length() );
117 printf("Fade length : %s\n", spctag_get_fadelength() );
118 printf("Artist : %s\n", spctag_get_artist() );
119 printf("Default channels : %s\n", spctag_get_defaultchannels() );
120 printf("Emulator : %s\n", spctag_get_emulator() );
121
122 // Close file
123 fclose( spc_file );
124
125 return 0;
126 }