Collect all of the various spread out 3rd party licenses to a single file.
[SquirrelJME.git] / nanocoat / tests / testDescClassName.c
blobb108507d72e06f6da51ca544d2321924332de27a
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <stdlib.h>
11 #include <string.h>
13 #include "mock.h"
14 #include "proto.h"
15 #include "sjme/util.h"
16 #include "test.h"
17 #include "unit.h"
19 /**
20 * Tests parsing of class names.
22 * @since 2024/02/04
24 SJME_TEST_DECLARE(testDescClassName)
26 sjme_desc_className* result;
27 sjme_lpcstr string;
28 sjme_jint strLen, strHash;
30 /* Setup default package. */
31 string = "Squeak";
32 strLen = strlen(string);
33 strHash = sjme_string_hash(string);
35 /* Parse. */
36 result = NULL;
37 if (!sjme_desc_interpretClassName(test->pool,
38 &result, string, strLen) ||
39 result == NULL)
40 return sjme_unit_fail(test, "Could not interpret class name?");
42 /* Check that it is valid. */
43 sjme_unit_equalI(test, strHash, result->hash,
44 "Hash incorrect?");
45 sjme_unit_isFalse(test, result->isField,
46 "Was a field?");
47 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
48 "Squeak"),
49 "Incorrect binary name?");
51 /* Setup base package. */
52 string = "Squeak/In/Box";
53 strLen = strlen(string);
54 strHash = sjme_string_hash(string);
56 /* Parse. */
57 result = NULL;
58 if (!sjme_desc_interpretClassName(test->pool,
59 &result, string, strLen) ||
60 result == NULL)
61 return sjme_unit_fail(test, "Could not interpret class name?");
63 /* Check validity. */
64 sjme_unit_equalI(test, strHash, result->hash,
65 "Hash incorrect?");
66 sjme_unit_isFalse(test, result->isField,
67 "Was a field?");
68 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
69 "Squeak/In/Box"),
70 "Incorrect binary name?");
72 /* Parse. */
73 result = NULL;
74 if (!sjme_desc_interpretClassName(test->pool,
75 &result, string, strLen) ||
76 result == NULL)
77 return sjme_unit_fail(test, "Could not interpret class name?");
79 /* Array type. */
80 string = "[LSqueak/In/Box;";
81 strLen = strlen(string);
82 strHash = sjme_string_hash(string);
84 /* Parse. */
85 result = NULL;
86 if (!sjme_desc_interpretClassName(test->pool,
87 &result, string, strLen) ||
88 result == NULL)
89 return sjme_unit_fail(test, "Could not interpret class name?");
91 /* Check. */
92 sjme_unit_equalI(test, strHash, result->hash,
93 "Hash incorrect?");
94 sjme_unit_isTrue(test, result->isField,
95 "Was a binary name?");
96 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
97 "[LSqueak/In/Box;"),
98 "Incorrect field name?");
100 /* Success! */
101 return SJME_TEST_RESULT_PASS;