From: <bi...@us...> - 2013-12-03 21:44:38
|
Revision: 9613 http://sourceforge.net/p/oorexx/code-0/9613 Author: bigrixx Date: 2013-12-03 21:44:35 +0000 (Tue, 03 Dec 2013) Log Message: ----------- [feature-requests:#364] Add some character constants to the string class Modified Paths: -------------- test/trunk/external/API/orxmethod.cpp test/trunk/ooRexx/API/oo/METHOD.testGroup Modified: test/trunk/external/API/orxmethod.cpp =================================================================== --- test/trunk/external/API/orxmethod.cpp 2013-12-03 21:39:27 UTC (rev 9612) +++ test/trunk/external/API/orxmethod.cpp 2013-12-03 21:44:35 UTC (rev 9613) @@ -2067,28 +2067,30 @@ return context->SetMutableBufferLength(b, l); } -RexxMethod0(size_t, TestMutableBufferCapacity, RexxMutableBufferObject, b) +RexxMethod1(size_t, TestMutableBufferCapacity, RexxMutableBufferObject, b) { - return context->MutableBufferCapactity(b); + return context->MutableBufferCapacity(b); } -RexxMethod1(size_t, TestSetMutableBufferCapacity, RexxMutableBufferObject, b, size_t, l) +RexxMethod2(size_t, TestSetMutableBufferCapacity, RexxMutableBufferObject, b, size_t, l) { context->SetMutableBufferCapacity(b, l); return context->MutableBufferCapacity(b); } -RexxMethod1(logical_t, TestIsMutableBuffer, RexxMutableBufferObject, b) +RexxMethod1(logical_t, TestIsMutableBuffer, RexxObjectPtr, b) { return context->IsMutableBuffer(b); } -RexxMethod1(RexxMutableBufferObject, TestSetMutableBufferValue, RexxMutableBufferObject, b, CSTRING, newValue) +RexxMethod2(RexxMutableBufferObject, TestSetMutableBufferValue, RexxMutableBufferObject, b, CSTRING, newValue) { size_t l = strlen(newValue); char * buffer = (char *)context->SetMutableBufferCapacity(b, l); + // must set the length first if we are extending, as the set + // will pad with nulls if it goes longer. + context->SetMutableBufferLength(b, l); memcpy(buffer, newValue, l); - context->SetMutableBufferLength(b, l); return b; } Modified: test/trunk/ooRexx/API/oo/METHOD.testGroup =================================================================== --- test/trunk/ooRexx/API/oo/METHOD.testGroup 2013-12-03 21:39:27 UTC (rev 9612) +++ test/trunk/ooRexx/API/oo/METHOD.testGroup 2013-12-03 21:44:35 UTC (rev 9613) @@ -2590,3 +2590,92 @@ tester = .METHODtester~new self~expectSyntax('88.900') tester~TestObjectToDoubleAlt('abc') + +::method testNewMutableBuffer + tester = .METHODtester~new + buffer = tester~TestNewMutableBuffer(100) + self~assertTrue(buffer~isA(.MutableBuffer)) + self~assertSame(100, buffer~getbuffersize) + self~assertSame(0, buffer~length) + +::method testMutableBufferLength + tester = .METHODtester~new + + buffer = .mutablebuffer~new("1234567890") + self~assertSame(10, tester~TestMutableBufferLength(buffer)) + + buffer = .mutablebuffer~new("") + self~assertSame(0, tester~TestMutableBufferLength(buffer)) + + buffer~append("abc") + self~assertSame(3, tester~TestMutableBufferLength(buffer)) + +::method testSetMutableBufferLength + tester = .METHODtester~new + + -- cap the buffer size so we can more easily test going over + buffer = .mutablebuffer~new("1234567890", 10) + + self~assertSame(3, tester~TestSetMutableBufferLength(buffer, 3)) + self~assertSame("123", buffer~string) + + self~assertSame(5, tester~TestSetMutableBufferLength(buffer, 5)) + self~assertSame("123"||"0000"x, buffer~string) + + self~assertSame(10, tester~TestSetMutableBufferLength(buffer, 15)) + self~assertSame("123"||"00000000000000"x, buffer~string) + +::method testMutableBufferCapacity + tester = .METHODtester~new + + buffer = .mutablebuffer~new("1234567890") + self~assertSame(256, tester~TestMutableBufferCapacity(buffer)) + + buffer = .mutablebuffer~new("1234567890", 10) + self~assertSame(10, tester~TestMutableBufferCapacity(buffer)) + + buffer~setBufferSize(100) + self~assertSame(100, tester~TestMutableBufferCapacity(buffer)) + + buffer~setBufferSize(0) + self~assertSame(10, tester~TestMutableBufferCapacity(buffer)) + +::method testSetMutableBufferCapacity + tester = .METHODtester~new + + buffer = .mutablebuffer~new("1234567890", 10) + self~assertSame(100, tester~TestSetMutableBufferCapacity(buffer, 100)) + self~assertSame(100, buffer~getBufferSize) + self~assertSame(10, buffer~length) + + -- does not lower the capacity, just ensures it is large enough for the + -- given. + self~assertSame(100, tester~TestSetMutableBufferCapacity(buffer, 50)) + self~assertSame(100, buffer~getBufferSize) + self~assertSame(10, buffer~length) + +::method testIsMutableBuffer + tester = .METHODtester~new + + buffer = .mutablebuffer~new("1234567890", 10) + self~assertTrue(tester~TestIsMutableBuffer(buffer)) + self~assertFalse(tester~TestIsMutableBuffer(buffer~string)) + +::method testSetGetMutableBuffer + tester = .METHODtester~new + + buffer = .mutablebuffer~new("1234567890", 10) + tester~TestSetMutableBufferValue(buffer, "abcdef") + self~assertSame(10, buffer~getBufferSize) + self~assertSame(6, buffer~length) + self~assertSame("abcdef", tester~TestGetMutableBufferValue(buffer)) + + -- now force the buffer to expand the size + tester~TestSetMutableBufferValue(buffer, "12345678901234567890") + self~assertSame(20, buffer~getBufferSize) + self~assertSame(20, buffer~length) + self~assertSame("12345678901234567890", buffer~string) + self~assertSame("12345678901234567890", tester~TestGetMutableBufferValue(buffer)) + + + |