Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testDescClassName.c
blob7399507609edec03041070c75202d497db987997
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 "sjme/nvm/descriptor.h"
11 #include <stdlib.h>
12 #include <string.h>
14 #include "mock.h"
15 #include "proto.h"
16 #include "sjme/util.h"
17 #include "test.h"
18 #include "unit.h"
20 /**
21 * Tests parsing of class names.
23 * @since 2024/02/04
25 SJME_TEST_DECLARE(testDescClassName)
27 sjme_desc_className* result;
28 sjme_lpcstr string;
29 sjme_jint strLen, strHash;
31 /* Setup default package. */
32 string = "Squeak";
33 strLen = strlen(string);
34 strHash = sjme_string_hash(string);
36 /* Parse. */
37 result = NULL;
38 if (!sjme_desc_interpretClassName(test->pool,
39 &result, string, strLen) ||
40 result == NULL)
41 return sjme_unit_fail(test, "Could not interpret class name?");
43 /* Check that it is valid. */
44 sjme_unit_equalI(test, strHash, result->hash,
45 "Hash incorrect?");
46 sjme_unit_isFalse(test, result->isField,
47 "Was a field?");
48 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
49 "Squeak"),
50 "Incorrect binary name?");
52 /* Setup base package. */
53 string = "Squeak/In/Box";
54 strLen = strlen(string);
55 strHash = sjme_string_hash(string);
57 /* Parse. */
58 result = NULL;
59 if (!sjme_desc_interpretClassName(test->pool,
60 &result, string, strLen) ||
61 result == NULL)
62 return sjme_unit_fail(test, "Could not interpret class name?");
64 /* Check validity. */
65 sjme_unit_equalI(test, strHash, result->hash,
66 "Hash incorrect?");
67 sjme_unit_isFalse(test, result->isField,
68 "Was a field?");
69 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
70 "Squeak/In/Box"),
71 "Incorrect binary name?");
73 /* Parse. */
74 result = NULL;
75 if (!sjme_desc_interpretClassName(test->pool,
76 &result, string, strLen) ||
77 result == NULL)
78 return sjme_unit_fail(test, "Could not interpret class name?");
80 /* Array type. */
81 string = "[LSqueak/In/Box;";
82 strLen = strlen(string);
83 strHash = sjme_string_hash(string);
85 /* Parse. */
86 result = NULL;
87 if (!sjme_desc_interpretClassName(test->pool,
88 &result, string, strLen) ||
89 result == NULL)
90 return sjme_unit_fail(test, "Could not interpret class name?");
92 /* Check. */
93 sjme_unit_equalI(test, strHash, result->hash,
94 "Hash incorrect?");
95 sjme_unit_isTrue(test, result->isField,
96 "Was a binary name?");
97 sjme_unit_equalI(test, 0, sjme_desc_compareClassS(result,
98 "[LSqueak/In/Box;"),
99 "Incorrect field name?");
101 /* Success! */
102 return SJME_TEST_RESULT_PASS;