-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMClassTests.class.st
70 lines (51 loc) · 1.83 KB
/
VMClassTests.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Class {
#name : #VMClassTests,
#superclass : #TestCase,
#instVars : [
'testString',
'vmclass'
],
#category : #'VMMaker-OriginalTests'
}
{ #category : #'initialize-release' }
VMClassTests >> initialize [
super initialize.
testString := 'hello world'.
]
{ #category : #running }
VMClassTests >> setUp [
super setUp.
vmclass := VMClass new.
]
{ #category : #tests }
VMClassTests >> testStrlen [
| testByteArray |
"Instances of String must be the correct length"
self assert: (vmclass strlen: testString) equals: testString size.
"Instances of ByteArray can optionally have trailing nulls"
testByteArray := testString asByteArray.
self assert: (vmclass strlen: testByteArray) equals: testString size.
testByteArray := testByteArray, (ByteArray new: 3).
self assert: (vmclass strlen: testByteArray) equals: testString size.
]
{ #category : #tests }
VMClassTests >> testStrncpy [
| stringA byteArrayA |
stringA := String new: 5.
vmclass strncpy: stringA _: testString _: stringA size.
self assert: stringA equals: 'hello'.
stringA := String new: testString size + 3.
vmclass strncpy: stringA _: testString _: stringA size.
self assert: stringA equals: (testString, (String new: 3)).
byteArrayA := ByteArray new: 5.
vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
self assert: byteArrayA equals: 'hello' asByteArray.
byteArrayA := ByteArray new: testString size + 3.
vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
self assert: byteArrayA equals: (testString, (String new: 3)) asByteArray.
"SVr4, 4.3BSD, C89, C99 require the destination space after the string be null filled"
byteArrayA := ByteArray new: testString size + 3.
byteArrayA atAllPut: 255.
vmclass strncpy: byteArrayA _: testString _: byteArrayA size.
self assert: byteArrayA equals: (testString, (String new: 3)) asByteArray.
]