Esempio n. 1
0
static void
compare_helper (char *a, char *b, int expected, fn test_fn) {
  semver_t verX = {};
  semver_t verY = {};

  semver_parse(a, &verX);
  semver_parse(b, &verY);

  int resolution = test_fn(verX, verY);
  assert(resolution == expected);

  semver_free(&verX);
  semver_free(&verY);
}
Esempio n. 2
0
int parseAppPackageJson(){
	packageJsonFile_t packageJson;
	int result = packageJson_file_parse("package.json", &packageJson);
	if(result != JSON_SUCCESS)
		return 0;
	if(!packageJson.versionFilter)
		return 0;
	semver_t unsupportedVersion, supportedVersion1, supportedVersion2;
	semver_parse("0.11.0", &unsupportedVersion);
	semver_parse("0.12.2", &supportedVersion1);
	semver_parse("0.13.1", &supportedVersion2);
	result = strcmp(packageJson.name, "nw-image-viewer") == 0
		&& packageJson.versionFilter->major == 0 && packageJson.versionFilter->minor == 12 && packageJson.versionFilter->patch == 2
		&& packageJson.versionFilterOperator[0] == '>' && packageJson.versionFilterOperator[1] == '='
		&& !packageJson_file_is_nw_version_OK(&packageJson, unsupportedVersion) && packageJson_file_is_nw_version_OK(&packageJson, supportedVersion1) && packageJson_file_is_nw_version_OK(&packageJson, supportedVersion2);
	packageJson_file_free(&packageJson);
	return result;
}
Esempio n. 3
0
void
test_free () {
  test_start("free");

  semver_t ver = {};
  char * str = "1.5.6";
  semver_parse(str, &ver);
  assert(ver.major == 1);
  assert(ver.patch == 6);
  semver_free(&ver);

  semver_t ver2 = {};
  char * str2 = "1.5.6-beta.1+12345";
  semver_parse(str2, &ver2);
  assert(ver2.prerelease != NULL);
  semver_free(&ver2);
  assert(ver2.prerelease == NULL);

  test_end();
}
Esempio n. 4
0
int main(void)
{
  semver_config(my_malloc, my_realloc, my_free, stderr);

  SemVer* semver = semver_parse("1.0.0-alpha+build.7621");
  assert(NULL != semver);

  char* version_string = semver_to_string(semver);
  assert(NULL != version_string);

  free(version_string);
  semver_destroy(semver);

  printf("TEST custom-allocators: %lu bytes handled.\n", total_memory);
  return 0 == total_memory ? EXIT_FAILURE : EXIT_SUCCESS;
}
Esempio n. 5
0
void
test_parse_minor() {
  test_start("parse_minor");

  char buf[] = "1.2";
  semver_t ver = {};

  int error = semver_parse(buf, &ver);

  assert(error == 0);
  assert(ver.major == 1);
  assert(ver.minor == 2);
  assert(ver.patch == 0);

  semver_free(&ver);

  test_end();
}
Esempio n. 6
0
void
test_parse_metadata() {
  test_start("parse_metadata");

  char buf[] = "1.2.12+20130313144700";
  semver_t ver = {};

  int error = semver_parse(buf, &ver);

  assert(error == 0);
  assert(ver.major == 1);
  assert(ver.minor == 2);
  assert(ver.patch == 12);
  assert(strcmp(ver.metadata, "20130313144700") == 0);

  semver_free(&ver);

  test_end();
}
Esempio n. 7
0
void
test_parse_prerelease() {
  test_start("parse_prerelease");

  char buf[] = "1.2.12-beta.alpha.1.1";
  semver_t ver = {};

  int error = semver_parse(buf, &ver);

  assert(error == 0);
  assert(ver.major == 1);
  assert(ver.minor == 2);
  assert(ver.patch == 12);
  assert(strcmp(ver.prerelease, "beta.alpha.1.1") == 0);

  semver_free(&ver);

  test_end();
}
Esempio n. 8
0
int main(int argc, const char* argv[])
{
  if (2 != argc)
  {
    printf("TEST to-string: Not enough arguments\n");
    return EXIT_FAILURE;
  }

  char* s;
  SemVer* version = semver_parse(argv[1]);
  assert(NULL != version);

  s = semver_to_string(version);
  printf("TEST to-string:  in: \"%s\"\n", argv[1]);
  printf("TEST to-string: out: \"%s\"\n", s);
  assert(NULL != s);
  assert(0 == strcmp(argv[1], s));

  free(s);
  semver_destroy(version);
  return EXIT_SUCCESS;
}
Esempio n. 9
0
void
test_satisfies() {
  test_start("semver_satisfies");

  struct test_case_match cases[] = {
    {"1", "0", ">=", 1},
    {"1", "3", ">=", 0},
    {"1", "1", ">=", 1},
    {"1.5", "0.8", ">=", 1},
    {"1.2", "2.2", ">=", 0},
    {"3.0", "1.5", ">=", 1},
    {"1.0", "1.0", ">=", 1},
    {"1.0.9", "1.0.0", ">=", 1},
    {"1.1.5", "1.1.9", ">=", 0},
    {"1.2.2", "1.2.9", ">=", 0},
    {"1.0.0", "1.0.0", ">=", 1},

    {"1", "0", "<=", 0},
    {"1", "3", "<=", 1},
    {"1", "1", "<=", 1},
    {"1.5", "0.8", "<=", 0},
    {"1.2", "2.2", "<=", 1},
    {"3.0", "1.5", "<=", 0},
    {"1.0", "1.0", "<=", 1},
    {"1.0.9", "1.0.0", "<=", 0},
    {"1.1.5", "1.1.9", "<=", 1},
    {"1.2.2", "1.2.9", "<=", 1},
    {"1.0.0", "1.0.0", "<=", 1},

    {"1", "0", "=", 0},
    {"1", "3", "=", 0},
    {"1", "1", "=", 1},
    {"1.5", "0.8", "=", 0},
    {"1.2", "2.2", "=", 0},
    {"3.0", "1.5", "=", 0},
    {"1.0", "1.0", "=", 1},
    {"1.0.9", "1.0.0", "=", 0},
    {"1.1.5", "1.1.9", "=", 0},
    {"1.2.2", "1.2.9", "=", 0},
    {"1.0.0", "1.0.0", "=", 1},

    {"1", "0", ">", 1},
    {"1", "3", ">", 0},
    {"1", "1", ">", 0},
    {"1.5", "0.8", ">", 1},
    {"1.2", "2.2", ">", 0},
    {"3.0", "1.5", ">", 1},
    {"1.0", "1.0", ">", 0},
    {"1.0.9", "1.0.0", ">", 1},
    {"1.1.5", "1.1.9", ">", 0},
    {"1.2.2", "1.2.9", ">", 0},
    {"1.0.0", "1.0.0", ">", 0},

    {"1", "0", "<", 0},
    {"1", "3", "<", 1},
    {"1", "1", "<", 0},
    {"1.5", "0.8", "<", 0},
    {"1.2", "2.2", "<", 1},
    {"3.0", "1.5", "<", 0},
    {"1.0", "1.0", "<", 0},
    {"1.0.9", "1.0.0", "<", 0},
    {"1.1.5", "1.1.9", "<", 1},
    {"1.2.2", "1.2.9", "<", 1},
    {"1.0.0", "1.0.0", "<", 0},

    {"1", "0", "^", 0},
    {"1", "3", "^", 0},
    {"1", "1", "^", 1},
    {"1.5", "0.8", "^", 0},
    {"1.2", "2.2", "^", 0},
    {"3.0", "1.5", "^", 0},
    {"1.0", "1.0", "^", 1},
    {"1.0.9", "1.0.0", "^", 1},
    {"1.1.5", "1.1.9", "^", 1},
    {"1.3.2", "1.1.9", "^", 1},
    {"1.1.2", "1.5.9", "^", 1},
    {"0.1.2", "1.5.9", "^", 0},
    {"0.1.2", "0.2.9", "^", 0},
    {"1.2.2", "1.2.9", "^", 1},
    {"1.0.0", "1.0.0", "^", 1},

    {"1", "0", "~", 0},
    {"1", "3", "~", 0},
    {"1", "1", "~", 1},
    {"1.5", "0.8", "~", 0},
    {"1.2", "2.2", "~", 0},
    {"3.0", "1.5", "~", 0},
    {"1.0", "1.0", "~", 1},
    {"1.0.9", "1.0.0", "~", 1},
    {"1.1.5", "1.1.9", "~", 1},
    {"1.1.9", "1.1.3", "~", 1},
    {"1.2.2", "1.3.9", "~", 0},
    {"1.0.0", "1.0.0", "~", 1},
  };

  for (int i = 0; i < 82; i++) {
    struct test_case_match args = cases[i];

    semver_t verX = {};
    semver_t verY = {};

    semver_parse(args.x, &verX);
    semver_parse(args.y, &verY);

    int resolution = semver_satisfies(verX, verY, args.op);
    assert(resolution == args.expected);


    semver_free(&verX);
    semver_free(&verY);
  }

  test_end();
}
Esempio n. 10
0
bool update_required(indexJsonFile_t *indexJson){
	semver_t currentVersion = {};
	semver_parse(NWJSMANAGER_VERSION, &currentVersion);
	return semver_compare(indexJson->nwjsmanagerLatestVersion, currentVersion) > 0 && indexJson->nwjsmanagerUrgentUpdate;
}