pace_listbox_repositories_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 PaceListBoxRepositoriesTest {
  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. PaceListBoxRepositoriesTest.add_tests ();
  12. string file_content = "# comment\n\n[options]\n#key = value\nkey2 = value2\noption\n\n" +
  13. "[repo1]\nServer = value\n\n" +
  14. "#[repo2]\n#Server = value\n#Include = value2";
  15. try {
  16. FileUtils.set_contents ( "pace_listbox_repositories_test.conf", file_content );
  17. } catch ( Error e ) {
  18. stderr.printf ( "Error creating config file (%s)\n", e.message );
  19. }
  20. Test.run ();
  21. return 0;
  22. }
  23. public static void add_tests () {
  24. Test.add_func ( "/pace/listbox_repositories", () => {
  25. ListBoxRepositories test_listbox = new ListBoxRepositories ();
  26. assert ( test_listbox is ListBoxRepositories );
  27. } );
  28. Test.add_func ( "/pace/listbox_repositories/set_repositories/get_repositories", () => {
  29. bool check = true;
  30. ListBoxRepositories test_listbox = new ListBoxRepositories ();
  31. ConfigFile test_file = new ConfigFile ( "pace_listbox_repositories_test.conf" );
  32. test_listbox.set_repositories ( test_file );
  33. Array<Section> repositories = test_file.get_repositories ();
  34. check = check && repositories.index ( 0 ).to_string () == "[repo1]\nServer = value\n";
  35. check = check && repositories.index ( 1 ).to_string () == "# [repo2]\n# Server = value\n# Include = value2\n";
  36. assert ( check );
  37. } );
  38. }
  39. }