static void setup_engine() {
  setup_fixture_path();
  system("rm -Rf /tmp/valid-copy && cp -R fixtures/valid /tmp/valid-copy && chmod -R 755 /tmp/valid-copy");
  item_cache_create(&item_cache, "/tmp/valid-copy", &item_cache_options);
  item_cache_load(item_cache);
  tagger_cache = create_tagger_cache(item_cache, NULL);
  tagger_cache->tag_retriever = &fetch_url;
  ce = create_classification_engine(item_cache, tagger_cache, &opts);
}
Exemple #2
0
static int start_classifier(char * corpus) {
	if (CLASSIFIER_OK != item_cache_create(&item_cache, corpus, &item_cache_options)) {
    fprintf(stderr, "Error opening classifier database file at %s: %s\n", corpus, item_cache_errmsg(item_cache));
    free_item_cache(item_cache);
    return EXIT_FAILURE;
  } else {
    item_cache_load(item_cache);
    tagger_cache = create_tagger_cache(item_cache, &tagger_cache_options);
    tagger_cache->tag_retriever = &fetch_url;
    tagger_cache->tag_index_retriever = &fetch_url;

    engine = create_classification_engine(item_cache, tagger_cache, &ce_options);
    return !ce_start(engine);
  }
}
} END_TEST

/************************************************************************
 * Initialization tests.
 ************************************************************************/

START_TEST(test_engine_initialization) {
  ItemCache *item_cache;
  item_cache_create(&item_cache, "/tmp/valid-copy", &item_cache_options);
  item_cache_load(item_cache);
  tagger_cache = create_tagger_cache(item_cache, NULL);
  ClassificationEngine *engine = create_classification_engine(item_cache, tagger_cache, &opts);
  assert_not_null(engine);
  assert_false(ce_is_running(engine));
  free_classification_engine(engine);
} END_TEST
} END_TEST

START_TEST(test_engine_starting_and_stopping) {
  ItemCache *item_cache;
  item_cache_create(&item_cache, "/tmp/valid-copy", &item_cache_options);
  item_cache_load(item_cache);
  tagger_cache = create_tagger_cache(item_cache, NULL);

  ClassificationEngine *engine = create_classification_engine(item_cache, tagger_cache, &opts);
  assert_not_null(engine);
  int start_code = ce_start(engine);
  assert_equal(1, start_code);
  assert_true(ce_is_running(engine));
  assert_equal(0, ce_num_jobs_in_system(engine));
  int stop_code = ce_stop(engine);
  assert_equal(1, stop_code);
  assert_false(ce_is_running(engine));
  free_classification_engine(engine);
} END_TEST