Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/tests/testconfig.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include <String.h>
#include "common.h"
#include "debug.h"
#include "collection.h"
#include "function.h"
#include "array.h"
#include "rule.h"
#include "namerule.h"
#include "qidgenerator.h"
#include "holemanager.h"
#include "filehandle.h"
#include "fiddata.h"
#include "matcher.h"
#include "string.h"
#include "unittest.h"

typedef struct TestConfig
{
  char *settingstring;
  char *escapedsettingstring;
  char *singleescaped;
} TestConfig;

static void *testconfig_setup(void)
{
  TestConfig *data = (TestConfig *)emalloc_fs(sizeof(*data));
  data->settingstring = estrdup_fs("a normal setting");
  data->escapedsettingstring = 
    estrdup_fs("an escaped \\) setting\\nand newline\\tand tabs\\r");
  data->singleescaped = estrdup_fs(
    "an escaped \\nstring that will only\\\\convert single \\) right paren");
  return data;
}

static void testconfig_teardown(void *data)
{
  TestConfig *testconfig = (TestConfig *)data;
  assert_valid(testconfig);

  free(testconfig->settingstring);
  free(testconfig->escapedsettingstring);
  free(testconfig->singleescaped);
}

static bool testconfig_convert_escaped(void *data)
{
  TestConfig *testconfig = (TestConfig *)data;
  assert_valid(testconfig);

  test_assert(strcmp(
    testconfig->settingstring, 
    string_convert_escaped(testconfig->settingstring)) == 0);
  test_assert(strcmp(
    "an escaped ) setting\nand newline\tand tabs\r",
    string_convert_escaped(testconfig->escapedsettingstring)) == 0);
  return true;
}

bool testconfig_single_convert(void *data)
{
  TestConfig *testconfig = (TestConfig *)data;
  assert_valid(testconfig);

  test_assert(strcmp(
    "an escaped \\nstring that will only\\\\convert single ) right paren",
    string_convert_single_escaped(testconfig->singleescaped, ')', ')')) == 0);
  return true;
}

static TestFixure testconfig_fixure =
{
  .setup    = testconfig_setup,
  .teardown = testconfig_teardown
};

static TestCaseNamePair testconfig_testcases[] =
{
  testcasenamepair_make(testconfig_convert_escaped)
};

AbstractTest *testconfig_testsuite(void)
{
  return (AbstractTest *)
    testsuite_make("testconfig", 
      testconfig_testcases, static_array_length(testconfig_testcases), 
      &testconfig_fixure);
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.