Subversion Repository Public Repository

litesoft

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.render;

import junit.framework.*;

import org.litesoft.commonfoundation.base.*;
import org.litesoft.commonfoundation.typeutils.*;

public class MockRectTest extends TestCase
{
    public static TestSuite suite()
    {
        return new TestSuite( MockRectTest.class );
    }

    public MockRectTest( String name )
    {
        super( name );
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    }

    public void testDistributeToChildren()
            throws Exception
    {
        assertDC( initDC( 10, 15, 1 ), 2, 1, 4, 0, 1, 1 );
        assertDC( initDC( 10, 15, 1 ), 2, -1, 4, 0, 1, 1 );

        assertDC( initDC( 10, 15, 1 ), 2, 0, 4, 0, 1, 1 );
        assertDC( initDC( 10, 15, 1 ), -2, 4, 0, 0, -1, -1 );

        assertDC( initDC( 10, 15, 1 ), 4, 2, 4, 1, 1, 2 );

        assertDC( initDC( 10, 15, 1 ), -4, 4, 0, -1, -2, -1 );

        assertDC( initDC( 0, 15, 1 ), -4, 4, 2, 0, -3, -1 );

        assertDC( initDC( 10, 15, 1 ), 3, 0, 0, 1, 1, 1 );

        assertDC( new DistributeToChildren().add( new ChildAdjustStruct( 0, 10 ) ), //
                  5, 0, 0, "DTC(1): 0 x 5" );

        assertDC( initDC( 10, 15, 1 ), -3, 0, 0, -1, -1, -1 );

        assertDC( new DistributeToChildren().add( new ChildAdjustStruct( 0, 10 ) ), //
                  -5, 0, 0, "DTC(1): 0 x -5" );

        assertDC( initDC( 10, 15, 1 ), -7, 0, 0, -3, -3, -1 );
    }

    private void assertDC( DistributeToChildren zDC, int pAdjustBy, int pInitLast, //
                           int pNewLast, int pNew0, int pNew2, int pNew4 )
    {
        assertDC( zDC, pAdjustBy, pInitLast, pNewLast,
                  "DTC(3): 0 x " + pNew0 + ", 2 x " + pNew2 + ", 4 x " + pNew4 );
    }

    private void assertDC( DistributeToChildren zDC, int pAdjustBy, int pInitLast, //
                           int pNewLast, String pDCtoString )
    {
        int zNewLast = zDC.distribute( pAdjustBy, pInitLast );

        assertEquals( pDCtoString, zDC.toString() );
        assertEquals( zDC.toString(), pNewLast, zNewLast );
    }

    private DistributeToChildren initDC( int p0ShrinkAllowed, int p2ShrinkAllowed, int p4ShrinkAllowed )
    {
        DistributeToChildren zDC = new DistributeToChildren();

        zDC.add( new ChildAdjustStruct( 0, p0ShrinkAllowed ) );
        zDC.add( new ChildAdjustStruct( 2, p2ShrinkAllowed ) );
        zDC.add( new ChildAdjustStruct( 4, p4ShrinkAllowed ) );
        return zDC;
    }

    private void assertToString( MockNativeRect pRect, String... pLines )
    {
        String zActual = pRect.toString();
        String zExpected = Strings.combineAsLines( pLines );
        assertEquals( zExpected, zActual + "\n" );
    }

    private void emptyProcessManagerAndAssertTCB( RenderHelperProcess pRenderHelperProcess )
            throws Exception
    {
        TestCallBack zCallBack = new TestCallBack();

        pRenderHelperProcess.addCallback( zCallBack );

        emptyProcessManagerAndAssertTCB( zCallBack );
    }

    private void emptyProcessManagerAndAssertTCB( TestCallBack pCallBack )
            throws Exception
    {
        emptyProcessManager();

        assertTrue( "CallBack NOT Called", pCallBack.isCompleted() );
    }

    private void emptyProcessManager()
            throws Exception
    {
        RenderProcessManager zRPM = RenderProcessManager.INSTANCE;
        while ( !zRPM.isEmpty() )
        {
            for ( RenderHelperProcess zProcess; null != (zProcess = zRPM.first()); )
            {
                zProcess.process();
            }
            Long zWhen = zRPM.whenIsNextDeferredProcess();
            if ( zWhen != null )
            {
                long zNow = System.currentTimeMillis();
                long zDelay = zWhen - zNow;
                if ( zDelay > 0 )
                {
                    Thread.sleep( zDelay );
                }
            }
        }
    }

    public void testToString()
            throws Exception
    {
        assertToString( mRoot, //
                        "Root (0,0)", //
                        "  HW (0,0)-(5,0)", //
                        "    Lefty (0!=64,0!=48)", //
                        "    VW (0,0)-(0,10)", //
                        "      Righty (0!=64,0!=48)", //
                        "      Native (0!=50,0!=40)" );

        mRoot.setAttached( true );

        Thread.sleep( 15 );

        assertToString( mRoot, //
                        "Root (133,98)", //
                        "  HW (133,98)-(5,0)", //
                        "    Lefty (64,48)", //
                        "    VW (64,98)-(0,10)", //
                        "      Righty (64,48)", //
                        "      Native (50,40)" );
    }

    private MockRootContainer mRoot;

    protected void setUp()
            throws Exception
    {
        super.setUp();
        RenderProcessManager.INSTANCE.clear();
        RenderProcessManager.setTimeSource( MillisecTimeSource.INSTANCE );
        mRoot = new MockRootContainer( 10, 10 ).setChild(
                new MockHorizontalWrappingContainer( "HW" ).setDecorationSizeX( 5 ).addChild(
                        new MockSizableRect( "Lefty", 64, 48, 32, 24 ),
                        new MockVerticalWrappingContainer( "VW" ).setDecorationSizeY( 10 ).addChild(
                                new MockSizableRect( "Righty", 64, 48, 32, 24 ),
                                new MockNativeRect( "Native", 50, 40 ) ) ) );
    }

    protected void tearDown()
            throws Exception
    {
        mRoot.setAttached( false );

        RenderProcessManager.INSTANCE.clear();
        RenderProcessManager.setTimeSource( MillisecTimeSource.INSTANCE );

        super.tearDown();
    }

    public void testSetSizeX_attach_then_size_and_slow_change()
            throws Exception
    {
        mRoot.setAttached( true );

        emptyProcessManager();

        assertToString( mRoot, //
                        "Root (133,98)", //
                        "  HW (133,98)-(5,0)", //
                        "    Lefty (64,98)", //
                        "    VW (64,98)-(0,10)", //
                        "      Righty (64,48)", //
                        "      Native (50,40)" );

        emptyProcessManagerAndAssertTCB( mRoot.setSizeX( 200 ) );// + 67

        assertToString( mRoot, //
                        "Root (200,98)", // + 67
                        "  HW (200,98)-(5,0)", //
                        "    Lefty (97,98)", // + 34
                        "    VW (98,98)-(0,10)", //
                        "      Righty (98,48)", // + 33
                        "      Native (50,40)" );

        assertNotNull( mRoot ); // For Debugging...
    }

    public void testSetSizeX_size_then_attach_bigger_then_smaller_then_tpp_small()
            throws Exception
    {
        TestCallBack zCallBack = new TestCallBack();

        RenderHelperProcess zHelperProcess = mRoot.setSizeX( 200 );// + 67
        zHelperProcess.addCallback( zCallBack );

        mRoot.setAttached( true );

        emptyProcessManagerAndAssertTCB( zCallBack );

        assertToString( mRoot, //
                        "Root (200,98)", // + 67
                        "  HW (200,98)-(5,0)", //
                        "    Lefty (97,98)", // + 34
                        "    VW (98,98)-(0,10)", //
                        "      Righty (98,48)", // + 33
                        "      Native (50,40)" );

        emptyProcessManagerAndAssertTCB( mRoot.setSizeX( 100 ) ); // - 100

        assertToString( mRoot, //
                        "Root (100,98)", // - 100
                        "  HW (100,98)-(5,0)", //
                        "    Lefty (45,98)", // - 53
                        "    VW (50,98)-(0,10)", //
                        "      Righty (50,48)", // -47
                        "      Native (50,40)" );

        emptyProcessManagerAndAssertTCB( mRoot.setSizeX( 50 ) ); // - 50

        assertToString( mRoot, //
                        "Root (50,98)", // - 50
                        "  HW (87,98)-(5,0)", // - 13
                        "    Lefty (32,98)", // - 13
                        "    VW (50,98)-(0,10)", //
                        "      Righty (50,48)", //
                        "      Native (50,40)" );

        emptyProcessManagerAndAssertTCB( mRoot.setSizeX( 100 ) ); // + 50

        assertToString( mRoot, //
                        "Root (100,98)", // - 100
                        "  HW (100,98)-(5,0)", //
                        "    Lefty (38,98)", // - 53
                        "    VW (57,98)-(0,10)", //
                        "      Righty (57,48)", // -47
                        "      Native (50,40)" );

    }

//    mRoot = new MockRootContainer( 10, 10 ).setChild(
//            new MockHorizontalWrappingContainer( "HW" ).setDecorationSizeX( 5 ).addChild(
//                    new MockSizableRect( "Lefty", 64, 48, 32, 24 ),
//                    new MockVerticalWrappingContainer( "VW" ).setDecorationSizeY( 10 ).addChild(
//                            new MockSizableRect( "Righty", 64, 48, 32, 24 ),
//                            new MockNativeRect( "Native", 50, 40 ) ) ) );

    private static class TestCallBack implements RenderHelperCallback
    {
        private volatile boolean mCompleted = false;

        public boolean isCompleted()
        {
            return mCompleted;
        }

        public void processCompleted( RenderHelperProcess pCompletedProcess,
                                      RenderProcessResult pCompletedProcessResult )
        {
            mCompleted = true;
        }
    }
}

Commits for litesoft/trunk/Java/core/jvm1.5/src/org/litesoft/render/MockRectTest.java

Diff revisions: vs.
Revision Author Commited Message
942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

858 Diff Diff GeorgeS picture GeorgeS Sun 04 Nov, 2012 18:40:40 +0000
851 Diff Diff GeorgeS picture GeorgeS Mon 08 Oct, 2012 00:05:32 +0000

Breaking the code as Temporal changes are implemented...

821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
819 Diff Diff GeorgeS picture GeorgeS Sat 18 Aug, 2012 18:09:40 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000