ObjectStoreJsunit.test.js 26.9 KB
Newer Older
Z
zhangmaowen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
1
18834416147 已提交
15
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
Z
zhangmaowen 已提交
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
import distributedObject from '@ohos.data.distributedDataObject';

var baseLine = 500; //0.5 second
const TAG = "OBJECTSTORE_TEST";

function changeCallback(sessionId, changeData) {
    console.info("get init change111" + sessionId + " " + changeData);
    if (changeData != null && changeData != undefined) {
        changeData.forEach(element => {
            console.info(TAG + "data changed !" + element);
        });
    }
    console.info(TAG + "get init change111 end" + sessionId + " " + changeData);
}

function changeCallback2(sessionId, changeData) {
    console.info("get init change222" + sessionId + " " + changeData);
    if (changeData != null && changeData != undefined) {
        changeData.forEach(element => {
            console.info(TAG + "data changed !" + element);
        });
    }
    console.info(TAG + "get init change222 end" + sessionId + " " + changeData);
}

function statusCallback1(sessionId, networkId, status) {
    console.info(TAG + "test init change111" + sessionId);
    this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId;
}

function statusCallback2(sessionId, networkId, status) {
    console.info(TAG + "test init change222" + sessionId);
    this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId;
}

function statusCallback3(sessionId, networkId, status) {
    console.info(TAG + "test init change333" + sessionId);
    this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId;
}

describe('objectStoreTest', function () {
    beforeAll(function () {
        console.info(TAG + 'beforeAll')
    })

    beforeEach(function () {
        console.info(TAG + 'beforeEach')
    })

    afterEach(function () {
        console.info(TAG + 'afterEach')
    })

    afterAll(function () {
        console.info(TAG + 'afterAll')
    })

    console.log(TAG + "*************Unit Test Begin*************");


    /**
     * @tc.name: testOn001
     * @tc.desc: object join session and on,object can receive callback when data has been changed
Y
yanglei1217 已提交
79
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_On_001
Z
zhangmaowen 已提交
80 81 82 83 84 85
     */
    it('testOn001', 0, function (done) {
        console.log(TAG + "************* testOn001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session1");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
86
            expect("session1" == objectTest.__sessionId);
Z
zhangmaowen 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        } else {
            console.log(TAG + "testOn001 joinSession failed");
        }
        console.info(TAG + " start call watch change");
        objectTest.on("change", changeCallback);
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testOn001 end *************");
    })

    /**
     * @tc.name: testOn002
     * @tc.desc object join session and no on,obejct can not receive callback when data has been changed
Y
yanglei1217 已提交
110
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_On_002
Z
zhangmaowen 已提交
111 112 113 114 115 116
     */
    it('testOn002', 0, function (done) {
        console.log(TAG + "************* testOn002 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session2");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
117
            expect("session2" == objectTest.__sessionId);
Z
zhangmaowen 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        } else {
            console.log(TAG + "testOn002 joinSession failed");
        }
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testOn002 end *************");
    })

    /**
     * @tc.name: testOn003
     * @tc.desc: object join session and on,then object change data twice,
     *           object can receive two callbacks when data has been changed
Y
yanglei1217 已提交
140
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_On_003
Z
zhangmaowen 已提交
141 142 143 144 145 146
     */
    it('testOn003', 0, function (done) {
        console.log(TAG + "************* testOn003 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session3");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
147
            expect("session3" == objectTest.__sessionId);
Z
zhangmaowen 已提交
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
        } else {
            console.log(TAG + "testOn003 joinSession failed");
        }
        objectTest.on("change", changeCallback);
        console.info(TAG + " start call watch change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            objectTest.name = "jack2";
            objectTest.age = 20;
            objectTest.isVis = false;
            expect(objectTest.name == "jack2");
            expect(objectTest.age == 20);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testOn003 end *************");
    })

    /**
     * @tc.name: testOn004
     * @tc.desc object join session and on,then object do not change data,object can not receive callbacks
Y
yanglei1217 已提交
176
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_On_004
Z
zhangmaowen 已提交
177 178 179 180 181 182
     */
    it('testOn004', 0, function (done) {
        console.log(TAG + "************* testOn004 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session4");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
183
            expect("session4" == objectTest.__sessionId);
Z
zhangmaowen 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197
        } else {
            console.log(TAG + "testOn004 joinSession failed");
        }
        objectTest.on("change", changeCallback);
        console.info(TAG + " start call watch change");
        console.info(TAG + " end call watch change");

        done()
        console.log(TAG + "************* testOn004 end *************");
    })

    /**
     * @tc.name testOff001
     * @tc.desc object join session and on&off,object can not receive callback after off
Y
yanglei1217 已提交
198
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Off_001
Z
zhangmaowen 已提交
199 200 201 202 203 204
     */
    it('testOff001', 0, function (done) {
        console.log(TAG + "************* testOff001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session5");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
205
            expect("session5" == objectTest.__sessionId);
Z
zhangmaowen 已提交
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
        } else {
            console.log(TAG + "testOff001 joinSession failed");
        }
        objectTest.on("change", changeCallback);
        console.info(TAG + " start call watch change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }
        objectTest.off("change");
        console.info(TAG + " end call watch change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack2";
            objectTest.age = 20;
            objectTest.isVis = false;
            expect(objectTest.name == "jack2");
            expect(objectTest.age == 20);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testOff001 end *************");
    })

    /**
     * @tc.name:testOff002
     * @tc.desc object join session and off,object can not receive callback
Y
yanglei1217 已提交
241
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Off_002
Z
zhangmaowen 已提交
242 243 244 245 246 247
     */
    it('testOff002', 0, function (done) {
        console.log(TAG + "************* testOff002 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session6");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
248
            expect("session6" == objectTest.__sessionId);
Z
zhangmaowen 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
        } else {
            console.log(TAG + "testOff002 joinSession failed");
        }
        objectTest.off("change");
        console.info(TAG + " end call watch change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testOff002 end *************");
    })

    /**
     * @tc.name: testMultiObjectOn001
     * @tc.desc: two objects join session and on,then object change data,user can receive two callbacks from two objects
Y
yanglei1217 已提交
272
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Multi_001
Z
zhangmaowen 已提交
273 274 275 276 277 278
     */
    it('testMultiObjectOn001', 0, function (done) {
        console.log(TAG + "************* testMultiObjectOn001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session7");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
279
            expect("session7" == objectTest.__sessionId);
Z
zhangmaowen 已提交
280 281 282 283 284 285
        } else {
            console.log(TAG + "testMultiObjectOn001 joinSession failed");
        }
        var testObject = distributedObject.createDistributedObject({ name: "Eric", age: 81, isVis: true });
        testObject.setSessionId("testSession1");
        if (testObject != undefined && testObject != null) {
1
18834416147 已提交
286
            expect("testSession1" == testObject.__sessionId);
Z
zhangmaowen 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300
        } else {
            console.log(TAG + "testMultiObjectOn001 joinSession failed");
        }
        objectTest.on("change", changeCallback);
        testObject.on("change", changeCallback2);
        console.info(TAG + " start call watch change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
1
18834416147 已提交
301 302 303 304 305 306 307 308 309 310 311
            console.info(TAG + " objectTest is null,set name fail");
        }
        if (testObject != undefined && testObject != null) {
            testObject.name = "jack2";
            testObject.age = 20;
            testObject.isVis = false;
            expect(testObject.name == "jack2");
            expect(testObject.age == 20);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " testObject is null,set name fail");
Z
zhangmaowen 已提交
312 313 314 315 316 317
        }

        done()
        console.log(TAG + "************* testMultiObjectOn001 end *************");
    })

1
18834416147 已提交
318 319 320 321 322
    /**
         * @tc.name: testMultiObjectOff001
         * @tc.desc: two objects join session and on&off,then two objects can not receive callbacks
         * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Multi_Off_001
         */
Y
yanglei1217 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    it('testMultiObjectOff001', 0, function (done) {
        console.log(TAG + "************* testMultiObjectOff001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session8");
        if (objectTest != undefined && objectTest != null) {
            expect("session8" == objectTest.__sessionId);
        } else {
            console.log(TAG + "testMultiObjectOn002 joinSession failed");
        }
        var testObject = distributedObject.createDistributedObject({ name: "Eric", age: 81, isVis: true });
        testObject.setSessionId("testSession2");
        if (testObject != undefined && testObject != null) {
            expect("testSession2" == testObject.__sessionId);
        } else {
            console.log(TAG + "testMultiObjectOn002 joinSession failed");
        }
        console.log(TAG + " start call watch change")
        objectTest.on("change", changeCallback);
        testObject.on("change", changeCallback2);
        console.info(TAG + " watch success");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack1";
            objectTest.age = 19;
            objectTest.isVis = true;
            expect(objectTest.name == "jack1");
            expect(objectTest.age == 19);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }
        if (testObject != undefined && testObject != null) {
            testObject.name = "jack2";
            testObject.age = 20;
            testObject.isVis = false;
            expect(testObject.name == "jack2");
            expect(testObject.age == 20);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }
        objectTest.off("change");
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = "jack3";
            objectTest.age = 21;
            objectTest.isVis = false;
            expect(objectTest.name == "jack3");
            expect(objectTest.age == 21);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }
        testObject.off("change");
        if (testObject != undefined && testObject != null) {
            testObject.name = "jack4";
            testObject.age = 22;
            testObject.isVis = true;
            expect(testObject.name == "jack4");
            expect(testObject.age == 22);
            console.info(TAG + " set data success!");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testMultiObjectOff001 end *************");
    })
1
18834416147 已提交
389 390

    /**
Y
yanglei1217 已提交
391 392 393 394
     * @tc.name: testChangeSession001
     * @tc.desc: objects join session,then change sessionId
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Session_001
     */
1
18834416147 已提交
395
    it('testChangeSession001', 0, function (done) {
Y
yanglei1217 已提交
396 397 398 399 400 401 402 403
        console.log(TAG + "************* testChangeSession001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session9");
        if (objectTest != undefined && objectTest != null) {
            expect("session9" == objectTest.__sessionId);
        } else {
            console.log(TAG + "testChangeSession001 joinSession failed");
        }
1
18834416147 已提交
404
        console.log(TAG + "start change sessionId");
Y
yanglei1217 已提交
405
        setTimeout(() => objectTest.setSessionId("session9"), 1000);
1
18834416147 已提交
406
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
407 408 409 410 411 412 413 414 415
            expect("session9" == objectTest.__sessionId);
        } else {
            console.log(TAG + "testChangeSession001 joinSession again failed");
        }

        done()
        console.log(TAG + "************* testChangeSession001 end *************");
    })

Z
zhangmaowen 已提交
416 417 418
    /**
     * @tc.name: testUndefinedType001
     * @tc.desc: object use undefined type,can not join session
Y
yanglei1217 已提交
419
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Type_001
Z
zhangmaowen 已提交
420 421 422 423 424 425 426
     */
    it('testUndefinedType001', 0, function (done) {
        console.log(TAG + "************* testUndefinedType001 start *************");
        var object1 = distributedObject.createDistributedObject({ name: undefined, age: undefined, isVis: undefined });
        try {
            object1.setSessionId("session11");
            if (object1 != undefined && object1 != null) {
Y
yanglei1217 已提交
427
                expect("session11" == object1.__sessionId);
Z
zhangmaowen 已提交
428
            } else {
Y
yanglei1217 已提交
429
                console.log(TAG + "testUndefinedType001 joinSession session11 failed");
Z
zhangmaowen 已提交
430 431 432 433 434 435 436 437 438 439 440 441
            }
        } catch (error) {
            console.error(TAG + error);
        }

        done()
        console.log(TAG + "************* testUndefinedType001 end *************");
    })

    /**
     * @tc.name: testGenSessionId001
     * @tc.desc: object generate random sessionId
Y
yanglei1217 已提交
442
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_GetSessionId_001
Z
zhangmaowen 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455
     */
    it('testGenSessionId001', 0, function (done) {
        console.log(TAG + "************* testGenSessionId001 start *************");
        var sessionId = distributedObject.genSessionId();
        expect(sessionId != null && sessionId.length > 0 && typeof (sessionId) == 'string');

        done()
        console.log(TAG + "************* testGenSessionId001 end *************");
    })

    /**
     * @tc.name: testGenSessionId002
     * @tc.desc: object generate 2 random sessionId and not equal
Y
yanglei1217 已提交
456
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_GetSessionId_002
Z
zhangmaowen 已提交
457 458
     */
    it('testGenSessionId002', 0, function (done) {
Y
yanglei1217 已提交
459
        console.log(TAG + "************* testGenSessionId002 start *************");
Z
zhangmaowen 已提交
460 461 462 463 464 465 466 467 468 469 470
        var sessionId1 = distributedObject.genSessionId();
        var sessionId2 = distributedObject.genSessionId();
        expect(sessionId1 != sessionId2);

        done()
        console.log(TAG + "************* testGenSessionId002 end *************");
    })

    /**
     * @tc.name: testOnStatus001
     * @tc.desc: object set a listener to watch another object online/offline
Y
yanglei1217 已提交
471
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_OnStatus_001
Z
zhangmaowen 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
     */
    it('testOnStatus001', 0, function (done) {
        console.log(TAG + "************* testOnStatus001 start *************");
        console.log(TAG + "start watch status");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.on("status", statusCallback1);
        console.log(TAG + "watch success");

        done()
        console.log(TAG + "************* testOnStatus001 end *************");
    })

    /**
     * @tc.name: testOnStatus002
     * @tc.desc: object set several listener and can unset specified listener
Y
yanglei1217 已提交
487
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_OnStatus_002
Z
zhangmaowen 已提交
488 489
     */
    it('testOnStatus002', 0, function (done) {
Y
yanglei1217 已提交
490
        console.log(TAG + "************* testOnStatus002 start *************");
Z
zhangmaowen 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        console.log(TAG + "start watch status");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.on("status", statusCallback1);
        objectTest.on("status", statusCallback2);
        objectTest.on("status", statusCallback3);
        console.log(TAG + "watch success");
        console.log(TAG + "start call unwatch status");
        objectTest.off("status", statusCallback1);
        console.log(TAG + "unwatch success");

        done()
        console.log(TAG + "************* testOnStatus002 end *************");
    })

    /**
     * @tc.name: testOnStatus003
     * @tc.desc: object set several listener and can unWatch all watcher
Y
yanglei1217 已提交
508
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_OnStatus_003
Z
zhangmaowen 已提交
509
     */
Y
yanglei1217 已提交
510 511
    it('testOnStatus003', 0, function (done) {
        console.log(TAG + "************* testOnStatus003 start *************");
Z
zhangmaowen 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
        console.log(TAG + "start watch status");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.on("status", statusCallback1);
        objectTest.on("status", statusCallback2);
        objectTest.on("status", statusCallback3);
        console.log(TAG + "watch success");
        console.log(TAG + "start call unwatch status");
        objectTest.off("status");
        console.log(TAG + "unwatch success");

        done()
        console.log(TAG + "************* testOnStatus003 end *************");
    })

    /**
     * @tc.name: testComplex001
     * @tc.desc: object can get/set complex data
Y
yanglei1217 已提交
529
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Complex_001
Z
zhangmaowen 已提交
530 531 532 533 534 535 536 537 538 539 540
     */
    it('testComplex001', 0, function (done) {
        console.log(TAG + "************* testComplex001 start *************");
        var complexObject = distributedObject.createDistributedObject({
            name: undefined,
            age: undefined,
            parent: undefined,
            list: undefined
        });
        complexObject.setSessionId("session12");
        if (complexObject != undefined && complexObject != null) {
Y
yanglei1217 已提交
541
            expect("session12" == complexObject.__sessionId);
Z
zhangmaowen 已提交
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
        } else {
            console.log(TAG + "testOnComplex001 joinSession session12 failed");
        }
        complexObject.name = "jack";
        complexObject.age = 19;
        complexObject.isVis = false;
        complexObject.parent = { mother: "jack mom", father: "jack Dad" };
        complexObject.list = [{ mother: "jack mom" }, { father: "jack Dad" }];
        expect(complexObject.name == "jack");
        expect(complexObject.age == 19);
        expect(complexObject.parent == { mother: "jack1 mom", father: "jack1 Dad" });
        expect(complexObject.list == [{ mother: "jack1 mom", father: "jack1 Dad" }]);

        done()
        console.log(TAG + "************* testComplex001 end *************");
    })

    /**
     * @tc.name: testMaxSize001
     * @tc.desc: object can get/set data under 4MB size
Y
yanglei1217 已提交
562
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_MaxSize_001
Z
zhangmaowen 已提交
563 564 565 566 567 568
     */
    it('testMaxSize001', 0, function (done) {
        console.log(TAG + "************* testMaxSize001 start *************");
        var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
        objectTest.setSessionId("session13");
        if (objectTest != undefined && objectTest != null) {
Y
yanglei1217 已提交
569
            expect("session13" == objectTest.__sessionId);
Z
zhangmaowen 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
        } else {
            console.log(TAG + "testMaxSize001 joinSession session13 failed");
        }
        //maxString = 32byte
        var maxString = "12345678123456781234567812345678".repeat(131072);
        if (objectTest != undefined && objectTest != null) {
            objectTest.name = maxString;
            objectTest.age = 42;
            objectTest.isVis = false;
            expect(objectTest.name == maxString);
            console.log(TAG + "get/set maxSize string success");
        } else {
            console.info(TAG + " object is null,set name fail");
        }

        done()
        console.log(TAG + "************* testMaxSize001 end *************");
    })

    /**
     * @tc.name: testPerformance001
     * @tc.desc: performanceTest for set/get data
Y
yanglei1217 已提交
592
     * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Performance_001
Z
zhangmaowen 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
     */
    it('testPerformance001', 0, function (done) {
        console.log(TAG + "************* testPerformance001 start *************");
        var complexObject = distributedObject.createDistributedObject({
            name: undefined,
            age: undefined,
            parent: undefined,
            list: undefined
        });
        var st1;
        var totalTime = 0;
        var setSessionIdTime = 0;
        var setTime = 0;
        var onTime = 0;
        var offTime = 0;
1
18834416147 已提交
608
        for (var i = 0; i < 100; i++) {
Z
zhangmaowen 已提交
609 610 611 612
            st1 = Date.now();
            complexObject.setSessionId("session14");
            setSessionIdTime += Date.now() - st1;
            if (complexObject != undefined && complexObject != null) {
Y
yanglei1217 已提交
613
                expect("session14" == complexObject.__sessionId);
Z
zhangmaowen 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
            } else {
                console.log(TAG + "testPerformance001 joinSession session14 failed");
            }
            console.info(TAG + " start call watch change");
            st1 = Date.now();
            complexObject.on("change", changeCallback);
            onTime += Date.now() - st1;
            console.info(TAG + "on change success");
            st1 = Date.now();
            complexObject.name = "jack2";
            complexObject.age = 20;
            complexObject.isVis = false;
            complexObject.parent = { mother: "jack1 mom1", father: "jack1 Dad1" };
            complexObject.list = [{ mother: "jack1 mom1" }, { father: "jack1 Dad1" }];
            setTime += Date.now() - st1;
            expect(complexObject.name == "jack2");
            expect(complexObject.age == 20);
            expect(complexObject.parent == { mother: "jack1 mom1", father: "jack1 Dad1" });
            expect(complexObject.list == [{ mother: "jack1 mom1", father: "jack1 Dad1" }]);

            console.log(TAG + "start unWatch change");
            st1 = Date.now();
            complexObject.off("change");
            offTime += Date.now() - st1;
            totalTime += setSessionIdTime;
            totalTime += setTime;
            totalTime += onTime;
            totalTime += offTime;
            console.log(TAG + "end unWatch success");
        }
        console.log(TAG + "totalTime = " + (totalTime / 100));
        expect(totalTime < baseLine);
        done()
        console.log(TAG + "************* testPerformance001 end *************");
    })

    console.log(TAG + "*************Unit Test End*************");
})