pace_selector_mirrorlist_files_test.vala 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* -*- Mode: Vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
  2. using Pace;
  3. using IniParser;
  4. class PaceSelectorMirrorlistFilesTest {
  5. public static int main ( string[] args ) {
  6. Test.init ( ref args );
  7. if ( !Gtk.init_check ( ref args ) )
  8. {
  9. return 77; //meson exit code to skip test
  10. }
  11. PaceSelectorMirrorlistFilesTest.add_tests ();
  12. string file_content = "Server = value\n" +
  13. "#Server = value2\n";
  14. try {
  15. FileUtils.set_contents ( "pace_selector_mirrorlist_files", file_content );
  16. } catch ( Error e ) {
  17. stderr.printf ( "Error creating mirrorlist file (%s)\n", e.message );
  18. }
  19. Test.run ();
  20. return 0;
  21. }
  22. public static void add_tests () {
  23. Test.add_func ( "/pace/selector_mirrorlist_files", () => {
  24. SelectorMirrorlistFiles test_selector = new SelectorMirrorlistFiles ();
  25. assert ( test_selector is SelectorMirrorlistFiles );
  26. } );
  27. Test.add_func ( "/pace/selector_mirrorlist_files/set_mirrorlist_files/get_current_mirrorlist_file", () => {
  28. bool check = true;
  29. SelectorMirrorlistFiles test_selector = new SelectorMirrorlistFiles ();
  30. Array<Mirrorlist> test_mirrorlists = new Array<Mirrorlist> ();
  31. test_mirrorlists.append_val ( new Mirrorlist ( "pace_selector_mirrorlist_files" ) );
  32. test_selector.set_mirrorlist_files ( test_mirrorlists );
  33. Array<Key> mirrors = test_selector.get_current_mirrorlist_file ().get_no_section_keys ();
  34. check = check && mirrors.index ( 0 ).to_string () == "Server = value\n";
  35. check = check && mirrors.index ( 1 ).to_string () == "# Server = value2\n";
  36. assert ( check );
  37. } );
  38. }
  39. }