コード例 #1
0
ファイル: e-cmd-application.c プロジェクト: Buzztrax/buzztrax
static void
test_bt_cmd_application_info_for_incomplete_file (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtCmdApplication *app = bt_cmd_application_new (TRUE);
  gchar *tmp_file_name =
      g_build_filename (g_get_tmp_dir (), "broken2.xml.txt", NULL);

  GST_INFO ("-- act --");
  gboolean ret = bt_cmd_application_info (app,
      check_get_test_song_path ("broken2.xml"), tmp_file_name);

  GST_INFO ("-- assert --");
  fail_unless (ret == TRUE, NULL);
  fail_unless (check_file_contains_str (NULL, tmp_file_name,
          "song.song_info.name: \"broken 2\""), NULL);
  fail_unless (check_file_contains_str (NULL, tmp_file_name,
          "song.setup.number_of_missing_machines: 1"), NULL);
  fail_unless (check_file_contains_str (NULL, tmp_file_name,
          "song.wavetable.number_of_missing_waves: 2"), NULL);

  GST_INFO ("-- cleanup --");
  g_unlink (tmp_file_name);
  g_free (tmp_file_name);
  ck_g_object_final_unref (app);
  BT_TEST_END;
}
コード例 #2
0
ファイル: e-cmd-application.c プロジェクト: Buzztrax/buzztrax
static void
test_bt_cmd_application_info (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtCmdApplication *app = bt_cmd_application_new (TRUE);
  gchar *tmp_file_name =
      g_build_filename (g_get_tmp_dir (), "test-simple1.xml.txt", NULL);

  GST_INFO ("-- act --");
  gboolean ret = bt_cmd_application_info (app,
      check_get_test_song_path ("test-simple1.xml"), tmp_file_name);

  GST_INFO ("-- assert --");
  fail_unless (ret == TRUE, NULL);
  fail_unless (check_file_contains_str (NULL, tmp_file_name,
          "song.song_info.name: \"test simple 1\""), NULL);

  GST_INFO ("-- cleanup --");
  g_unlink (tmp_file_name);
  g_free (tmp_file_name);
  ck_g_object_final_unref (app);
  BT_TEST_END;
}
コード例 #3
0
gint
main (gint argc, gchar ** argv)
{
  gboolean res = FALSE;
  gboolean arg_version = FALSE;
  gboolean arg_quiet = FALSE;
  gchar *command = NULL, *input_file_name = NULL, *output_file_name = NULL;
  gint saved_argc = argc;
  BtCmdApplication *app;
  GOptionContext *ctx;
  GOptionGroup *group;
  GError *err = NULL;

#ifdef ENABLE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif /* ENABLE_NLS */

  static GOptionEntry options[] = {
    {"version", '\0', 0, G_OPTION_ARG_NONE, NULL,
        N_("Print application version"), NULL},
    {"quiet", 'q', 0, G_OPTION_ARG_NONE, NULL, N_("Be quiet"), NULL},
    {"command", 'c', 0, G_OPTION_ARG_STRING, NULL, N_("Command name"),
        "{info, play, convert, encode}"},
    {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, NULL, N_("Input file name"),
        N_("<songfile>")},
    {"output-file", 'o', 0, G_OPTION_ARG_FILENAME, NULL, N_("Output file name"),
        N_("<songfile>")},
    {NULL}
  };
  // setting this separately gets us from 76 to 10 instructions
  options[0].arg_data = &arg_version;
  options[1].arg_data = &arg_quiet;
  options[2].arg_data = &command;
  options[3].arg_data = &input_file_name;
  options[4].arg_data = &output_file_name;

  // init libraries
  ctx = g_option_context_new (NULL);
  //g_option_context_add_main_entries(ctx, options, GETTEXT_PACKAGE);
  group =
      g_option_group_new ("main", _("buzztrax-cmd options"),
      _("Show buzztrax-cmd options"), argv[0], NULL);
  g_option_group_add_entries (group, options);
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
  g_option_context_set_main_group (ctx, group);

  bt_init_add_option_groups (ctx);
  g_option_context_add_group (ctx, btic_init_get_option_group ());

  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", safe_string (err->message));
    g_option_context_free (ctx);
    exit (1);
  }
  if (arg_version) {
    g_printf ("%s from " PACKAGE_STRING "\n", argv[0]);
    res = TRUE;
    goto Done;
  }
  if (!command) {
    if (argc == saved_argc) {
      usage (argc, argv, ctx);
    }
    goto Done;
  }

  GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "bt-cmd", 0,
      "music production environment / command ui");
  GST_INFO ("starting: command=\"%s\" input=\"%s\" output=\"%s\"", command,
      input_file_name, output_file_name);

  // give some global context info
  g_set_prgname ("buzztrax-cmd");
  g_set_application_name ("Buzztrax");
  g_setenv ("PULSE_PROP_application.icon_name", "buzztrax", TRUE);
  g_setenv ("PULSE_PROP_media.role", "production", TRUE);

  app = bt_cmd_application_new (arg_quiet);


  // set a default command, if a file is given
  if (!command && BT_IS_STRING (input_file_name)) {
    command = g_strdup ("p");
  }
  // depending on the options call the correct method
  if (!strcmp (command, "p") || !strcmp (command, "play")) {
    if (!BT_IS_STRING (input_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_play (app, input_file_name);
  } else if (!strcmp (command, "i") || !strcmp (command, "info")) {
    if (!BT_IS_STRING (input_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_info (app, input_file_name, output_file_name);
  } else if (!strcmp (command, "c") || !strcmp (command, "convert")) {
    if (!BT_IS_STRING (input_file_name) || !BT_IS_STRING (output_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_convert (app, input_file_name, output_file_name);
  } else if (!strcmp (command, "e") || !strcmp (command, "encode")) {
    if (!BT_IS_STRING (input_file_name) || !BT_IS_STRING (output_file_name))
      usage (argc, argv, ctx);
    res = bt_cmd_application_encode (app, input_file_name, output_file_name);
  } else
    usage (argc, argv, ctx);

  // free application
  g_object_unref (app);

Done:
  g_free (command);
  g_free (input_file_name);
  g_free (output_file_name);
  g_option_context_free (ctx);

  return !res;
}