#define _POSIX_C_SOURCE 200809L #include "xtc/xtc_settings.h" #include #include #include #include #include #define CHECK(x) do {if(!(x)){fprintf(stderr,"%d: %s\n",__LINE__,#x);return 1;}}while(0) int main(void) { char path[]="/tmp/xtc-settings-XXXXXX",value[4096]; int fd=mkstemp(path); size_t i,n; xtc_settings a,b,before; struct stat st; FILE *f; CHECK(fd>=0);close(fd);unlink(path); xtc_settings_defaults(&a);CHECK(xtc_settings_validate(&a)==XTC_OK); b=a;CHECK(xtc_settings_load(&b,path)==XTC_ERR_NOT_FOUND); strcpy(a.clap_paths,"~/space folder:/tmp/quoted\"name\\path");a.loop_enabled=1;a.follow_playhead=1;a.transport_detached=1;a.mixer_detached=1;a.transport_x=-30000;a.transport_width=400;a.note_velocity=87;strcpy(a.midi_input_port,"Keyboard:out");strcpy(a.midi_output_port,"Synth:in");a.midi_input_channel=2;a.midi_output_channel=4;a.midi_thru=1; CHECK(xtc_settings_save(&a,path)==XTC_OK);CHECK(stat(path,&st)==0 && (st.st_mode&0777)==0600); CHECK(xtc_settings_load(&b,path)==XTC_OK);CHECK(memcmp(&a,&b,sizeof(a))==0); xtc_settings_schema(&n); for(i=0;i=0);CHECK(fclose(f)==0);before=b;CHECK(xtc_settings_load(&b,path)==XTC_ERR_FORMAT);CHECK(memcmp(&before,&b,sizeof(b))==0);}} f=fopen(path,"wb");CHECK(f);CHECK(fwrite(";x\0hidden",1,9,f)==9);fclose(f);CHECK(xtc_settings_load(&b,path)==XTC_ERR_FORMAT); CHECK(xtc_settings_save(&a,path)==XTC_OK);b=a;b.loop_end=b.loop_start;CHECK(xtc_settings_save(&b,path)==XTC_ERR_INVALID_ARGUMENT);CHECK(xtc_settings_load(&b,path)==XTC_OK && b.loop_end==a.loop_end); CHECK(xtc_settings_save(&a,"/no-such-xtc-directory/settings")==XTC_ERR_IO); CHECK(xtc_settings_path(value,sizeof(value))==XTC_OK && strstr(value,"/.xtc.conf")); unlink(path);puts("Preferences INI validation, roundtrip, permissions and failure tests passed.");return 0; }