lstat.test.js 51.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) 2021 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.
 */

import {
  fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum, isBoolean,
  describe, beforeAll, beforeEach, afterEach, afterAll, it, expect,
} from '../../Common';

describe('fileio_lstat', function () {

  /**
24
   * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0000
25 26 27
   * @tc.name fileio_lstat_sync_000
   * @tc.desc Test Lstat.lstatSync() interface.
   * This interface shall work properly in normal case.
28 29 30 31
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
32
   */
33 34
  it('fileio_lstat_sync_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_sync_000');
35 36 37 38 39 40 41 42 43 44 45 46 47
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat !== null).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_sync_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
48
   * @tc.number SUB_DF_FILEIO_LSTAT_SYNC_0010
49 50 51
   * @tc.name fileio_lstat_sync_001
   * @tc.desc Test Lstat.lstatSync() interface.
   * This interface shall throw an exception when the file isnt's exist.
52 53 54 55
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
56
   */
57 58
  it('fileio_lstat_sync_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_sync_001');
59 60 61 62 63

    try {
      fileio.lstatSync(fpath);
      expect(null).assertFail();
    } catch (e) {
S
Storage sandboxing 已提交
64
      console.log('fileio_lstat_sync_001 has failed for ' + e);
65 66 67 68
    }
  });

  /**
69
   * @tc.number SUB_DF_FILEIO_LSTAT_DEV_0000
70 71
   * @tc.name fileio_lstat_dev_000
   * @tc.desc Test the dev member of class Lstat.
72 73 74 75
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
76
   */
77 78
  it('fileio_lstat_dev_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_dev_000');
79 80 81 82 83 84 85 86 87 88 89 90 91
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.dev)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_dev_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
92
   * @tc.number SUB_DF_FILEIO_LSTAT_INO_0000
93 94
   * @tc.name fileio_lstat_ino_000
   * @tc.desc Test the ino member of class Lstat
95 96 97 98
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
99
   */
100 101
  it('fileio_lstat_ino_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_ino_000');
102 103 104 105 106 107 108 109 110 111 112 113
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.ino)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_ino_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
114
   * @tc.number SUB_DF_FILEIO_LSTAT_MODE_0000
115 116
   * @tc.name fileio_lstat_mode_000
   * @tc.desc Test the mode member of class Lstat
117 118 119 120
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
121
   */
122 123
  it('fileio_lstat_mode_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_mode_000');
124 125 126 127 128 129 130 131 132 133 134 135 136
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.mode)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_mode_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
137
   * @tc.number SUB_DF_FILEIO_LSTAT_NLINK_0000
138 139
   * @tc.name fileio_lstat_nlink_000
   * @tc.desc Test the nlink member of class Lstat
140 141 142 143
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
144
   */
145 146
  it('fileio_lstat_nlink_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_nlink_000');
147 148 149 150 151 152 153 154 155 156 157 158 159
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.nlink)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_nlink_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
160
   * @tc.number SUB_DF_FILEIO_LSTAT_UID_0000
161 162
   * @tc.name fileio_lstat_uid_000
   * @tc.desc Test the uid member of class Lstat
163 164 165 166
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
167
   */
168 169
  it('fileio_lstat_uid_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_uid_000');
170 171 172 173 174 175 176 177 178 179 180 181 182
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.uid)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_uid_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
183
   * @tc.number SUB_DF_FILEIO_LSTAT_GID_0000
184 185
   * @tc.name fileio_lstat_gid_000
   * @tc.desc Test the gid member of class Lstat
186 187 188 189
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
190
   */
191 192
  it('fileio_lstat_gid_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_gid_000');
193 194 195 196 197 198 199 200 201 202 203 204 205
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.gid)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_gid_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
206
   * @tc.number SUB_DF_FILEIO_LSTAT_RDEV_0000
207 208
   * @tc.name fileio_lstat_rdev_000
   * @tc.desc Test the rdev member of class Lstat
209 210 211 212
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
213
   */
214 215
  it('fileio_lstat_rdev_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_rdev_000');
216 217 218 219 220 221 222 223 224 225 226 227 228
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.rdev)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_rdev_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
229
   * @tc.number SUB_DF_FILEIO_LSTAT_SIZE_0000
230 231
   * @tc.name fileio_lstat_size_000
   * @tc.desc Test the size member of class Lstat
232 233 234 235
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
236
   */
237 238
  it('fileio_lstat_size_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_size_000');
239 240 241 242 243 244 245 246 247 248 249 250 251
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.size)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_size_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
252
   * @tc.number SUB_DF_FILEIO_LSTAT_BLOCKS_0000
253 254
   * @tc.name fileio_lstat_blocks_000
   * @tc.desc Test the blocks member of class Lstat
255 256 257 258
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
259
   */
260 261
  it('fileio_lstat_blocks_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_blocks_000');
262 263 264 265 266 267 268 269 270 271 272 273 274
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.blocks)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_blocks_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
275
   * @tc.number SUB_DF_FILEIO_LSTAT_ATIME_0000
276 277
   * @tc.name fileio_lstat_atime_000
   * @tc.desc Test the atime member of class Lstat
278 279 280 281
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
282
   */
283 284
  it('fileio_lstat_atime_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_atime_000');
285 286 287 288 289 290 291 292 293 294 295 296 297
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.atime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_atime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
298
   * @tc.number SUB_DF_FILEIO_LSTAT_MTIME_0000
299 300
   * @tc.name fileio_lstat_mtime_000
   * @tc.desc Test the mtime member of class Lstat
301 302 303 304
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
305
   */
306 307
  it('fileio_lstat_mtime_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_mtime_000');
308 309 310 311 312 313 314 315 316 317 318 319 320
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.mtime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_mtime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
321
   * @tc.number SUB_DF_FILEIO_LSTAT_CTIME_0000
322 323
   * @tc.name fileio_lstat_ctime_000
   * @tc.desc Test the ctime member of class Lstat
324 325 326 327
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
328
   */
329 330
  it('fileio_lstat_ctime_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_ctime_000');
331 332 333 334 335 336 337 338 339 340 341 342 343
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.ctime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_ctime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
344
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0000
345 346 347
   * @tc.name fileio_lstat_is_block_device_000
   * @tc.desc Test the isBlockDevice() method of class Lstat.
   * This interface shall return a boolean variable.
348 349 350 351
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
352
   */
353 354
  it('fileio_lstat_is_block_device_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_block_device_000');
355 356 357 358 359 360 361 362 363 364 365 366 367
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isBlockDevice())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_block_device_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
368
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0010
369 370 371
   * @tc.name fileio_lstat_is_block_device_001
   * @tc.desc Test the isBlockDevice() method of class Lstat.
   * This interface shall not treat a normal file as a block special device.
372 373 374 375
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
376
   */
377 378
  it('fileio_lstat_is_block_device_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_block_device_001');
379 380 381 382 383 384 385 386 387 388 389 390 391
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isBlockDevice() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_block_device_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
392
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_BLOCK_DEVICE_0020
393 394
   * @tc.name fileio_test_lstat_is_block_device_002
   * @tc.desc Test Lstat.isBlockDevice() interface.
395 396 397 398
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
399
   */
400 401
  it('fileio_test_lstat_is_block_device_002', 0, async function () {
    let fpath = await nextFileName('fileio_test_lstat_is_block_device_002');
402 403 404 405 406 407 408 409 410 411 412 413
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isBlockDevice(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    }
  });

  /**
414
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0000
415 416 417
   * @tc.name fileio_lstat_is_character_device_000
   * @tc.desc Test Lstat.isCharacterDevice() interface.
   * This interface shall return a boolean variable.
418 419 420 421
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
422
   */
423 424
  it('fileio_lstat_is_character_device_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_character_device_000');
425 426 427 428 429 430 431 432 433 434 435 436 437
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isCharacterDevice())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_character_device_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
438
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0010
439 440 441
   * @tc.name fileio_lstat_is_character_device_001
   * @tc.desc Test Lstat.isCharacterDevice() interface.
   * This interface shall not treat a normal file as a character special device.
442 443 444 445
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
446
   */
447 448
  it('fileio_lstat_is_character_device_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_character_device_001');
449 450 451 452 453 454 455 456 457 458 459 460 461
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isCharacterDevice() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_character_device_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
462
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_CHARACTER_DEVICE_0020
463 464
   * @tc.name fileio_test_lstat_is_character_device_002
   * @tc.desc Test Lstat.isCharacterDevice() interface.
465 466 467 468
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
469
   */
470 471
  it('fileio_test_lstat_is_character_device_002', 0, async function () {
    let fpath = await nextFileName('fileio_test_lstat_is_character_device_002');
472 473 474 475 476 477 478 479 480 481 482 483
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isCharacterDevice(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    }
  });

  /**
484
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0000
485 486 487
   * @tc.name fileio_lstat_is_directory_000
   * @tc.desc Test Lstat.isDirectory() interface.
   * This interface shall return a boolean variable.
488 489 490 491
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
492
   */
493 494
  it('fileio_lstat_is_directory_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_directory_000');
495 496 497 498 499 500 501 502 503 504 505 506 507
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isDirectory())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_directory_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
508
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0010
509 510 511
   * @tc.name fileio_lstat_is_directory_001
   * @tc.desc Test Lstat.isDirectory() interface.
   * This interface shall not treat a normal file as a directory.
512 513 514 515
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
516
   */
517 518
  it('fileio_lstat_is_directory_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_directory_001');
519 520 521 522 523 524 525 526 527 528 529 530 531
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isDirectory() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_directory_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
532
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0020
533 534 535
   * @tc.name fileio_lstat_is_directory_002
   * @tc.desc Test Lstat.isDirectory() interface.
   * This interface shall not treat a normal file as a directory.
536 537 538 539
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
540
   */
541 542
  it('fileio_lstat_is_directory_002', 0, async function () {
    let dpath = await nextFileName('fileio_lstat_is_directory_002') + 'd';
543 544 545 546 547 548 549 550 551 552 553 554 555

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = fileio.lstatSync(dpath);
      expect(stat.isDirectory()).assertTrue();
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_directory_002 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
556
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_DIRECTORY_0030
557 558
   * @tc.name fileio_lstat_is_directory_003
   * @tc.desc Test Lstat.isDirectory() interface.
559 560 561 562
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
563
   */
564 565
  it('fileio_lstat_is_directory_003', 0, async function () {
    let dpath = await nextFileName('fileio_lstat_is_directory_003') + 'd';
566 567 568 569 570 571 572 573 574 575 576 577

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = fileio.lstatSync(dpath);
      expect(stat.isDirectory(-1)).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
    }
  });

  /**
578
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0000
579 580 581
   * @tc.name fileio_lstat_is_fifo_000
   * @tc.desc Test Lstat.isFIFO() interface.
   * This interface shall return a boolean variable.
582 583 584 585
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
586
   */
587 588
  it('fileio_lstat_is_fifo_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_fifo_000');
589 590 591 592 593 594 595 596 597 598 599 600 601
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isFIFO())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_fifo_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
602
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0010
603 604 605
   * @tc.name fileio_lstat_is_fifo_001
   * @tc.desc Test Lstat.isFIFO() interface.
   * This interface shall not treat a normal file as a FIFO.
606 607 608 609
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
610
   */
611 612
  it('fileio_lstat_is_fifo_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_fifo_001');
613 614 615 616 617 618 619 620 621 622 623 624 625
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isFIFO() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_fifo_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
626
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FIFO_0020
627 628
   * @tc.name fileio_test_stat_is_fifo_002
   * @tc.desc Test Lstat.isFIFO() interface.
629 630 631 632
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
633
   */
634 635
  it('fileio_test_lstat_is_fifo_002', 0, async function () {
    let fpath = await nextFileName('fileio_test_lstat_is_fifo_002');
636 637 638 639 640 641 642 643 644 645 646 647
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isFIFO(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    }
  });

  /**
648
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0000
649 650 651
   * @tc.name fileio_lstat_is_file_000
   * @tc.desc Test Lstat.isFile() interface.
   * This interface shall return a boolean variable.
652 653 654 655
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
656
   */
657 658
  it('fileio_lstat_is_file_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_file_000');
R
raoxian 已提交
659
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
660 661 662 663 664 665 666 667 668 669 670 671

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isFile())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_file_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
672
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0010
673 674 675
   * @tc.name fileio_lstat_is_file_001
   * @tc.desc Test Lstat.isFile() interface.
   * This interface shall treat a normal file as a normal file.
676 677 678 679
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
680
   */
681 682
  it('fileio_lstat_is_file_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_file_001');
R
raoxian 已提交
683
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
684 685 686 687 688 689 690 691 692 693 694 695

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isFile()).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_file_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
696
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0020
697 698 699
   * @tc.name fileio_lstat_is_file_002
   * @tc.desc Test Lstat.isFile() interface.
   * This interface shall not treat a directory as a normal file.
700 701 702 703
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
704
   */
705 706
  it('fileio_lstat_is_file_002', 0, async function () {
    let dpath = await nextFileName('fileio_lstat_is_file_002');
707 708 709 710 711 712 713 714 715 716 717 718 719

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = fileio.lstatSync(dpath);
      expect(stat.isFile() === false).assertTrue();
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_file_002 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
720
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_FILE_0030
721 722
   * @tc.name fileio_test_lstat_is_file_003
   * @tc.desc Test Lstat.isFile() interface.
723 724 725 726
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
727
   */
728 729
  it('fileio_test_lstat_is_file_003', 0, async function () {
    let dpath = await nextFileName('fileio_test_lstat_is_file_003');
730 731 732 733 734 735 736 737 738 739 740 741

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = fileio.lstatSync(dpath);
      expect(stat.isFile(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
    }
  });

  /**
742
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0000
743 744 745
   * @tc.name fileio_lstat_is_socket_000
   * @tc.desc Test Lstat.isSocket() interface.
   * This interface shall return a boolean variable.
746 747 748 749
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
750
   */
751 752
  it('fileio_lstat_is_socket_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_socket_000');
753 754 755 756 757 758 759 760 761 762 763 764 765
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isSocket())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_socket_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
766
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0010
767 768 769
   * @tc.name fileio_lstat_is_socket_001
   * @tc.desc Test Lstat.isSocket() interface.
   * This interface shall not treat a file as a socket.
770 771 772 773
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
774
   */
775 776
  it('fileio_lstat_is_socket_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_socket_001');
777 778 779 780 781 782 783 784 785 786 787 788 789
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isSocket() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_socket_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
790
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SOCKET_0020
791 792
   * @tc.name fileio_test_lstat_is_socket_002
   * @tc.desc Test Lstat.isSocket() interface.
793 794 795 796
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
797
   */
798 799
  it('fileio_test_lstat_is_socket_002', 0, async function () {
    let fpath = await nextFileName('fileio_test_lstat_is_socket_002');
800 801 802 803 804 805 806 807 808 809 810 811
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isSocket(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    }
  });

  /**
812
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0000
813 814 815
   * @tc.name fileio_lstat_is_symbolic_link_000
   * @tc.desc Test Lstat.isSymbolicLink() interface.
   * This interface shall return a boolean variable.
816 817 818 819
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
820
   */
821 822
  it('fileio_lstat_is_symbolic_link_000', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_symbolic_link_000');
823 824 825 826 827 828 829 830 831 832 833 834 835
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isBoolean(stat.isSymbolicLink())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_symbolic_link_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
836
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0010
837 838 839
   * @tc.name fileio_lstat_is_symbolic_link_001
   * @tc.desc Test Lstat.isSymbolicLink() interface.
   * This interface shall not treat a normal file as a symbolic link.
840 841 842 843
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
844
   */
845 846
  it('fileio_lstat_is_symbolic_link_001', 0, async function () {
    let fpath = await nextFileName('fileio_lstat_is_symbolic_link_001');
847 848 849 850 851 852 853 854 855 856 857 858 859
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isSymbolicLink() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_lstat_is_symbolic_link_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
860
   * @tc.number SUB_DF_FILEIO_LSTAT_IS_SYMBOLIC_LINK_0020
861 862
   * @tc.name fileio_test_lstat_is_symbolic_link_002
   * @tc.desc Test Lstat.isSymbolicLink() interface.
863 864 865 866
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
867
   */
868 869
  it('fileio_test_lstat_is_symbolic_link_002', 0, async function () {
    let fpath = await nextFileName('fileio_test_lstat_is_symbolic_link_002');
870 871 872 873 874 875 876 877 878 879 880 881
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(stat.isSymbolicLink(-1) === false).assertTrue();
      expect(null).assertFail();
    } catch (e) {
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    }
  });

  /**
882
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0000
883 884 885
   * @tc.name fileio_lstat_async_000
   * @tc.desc Test Stat.lstatAsync() interface.
   * This interface shall work properly in normal case when providing the promise async model.
886 887 888 889
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
890 891
   */
  it('fileio_lstat_async_000', 0, async function (done) {
892
    let fpath = await nextFileName('fileio_lstat_async_000');
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      fileio.lstat(fpath).then((stat) => {
        expect(stat !== null).assertTrue();
        expect(fileio.unlinkSync(fpath) == null).assertTrue();
      });
      done();
    } catch (e) {
      console.log('fileio_lstat_async_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
908
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0010
909 910 911
   * @tc.name fileio_lstat_async_001
   * @tc.desc Test Stat.lstatAsync() interface.
   * This interface shall work properly in normal case when providing the callback async model.
912 913 914 915
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
916 917
   */
  it('fileio_lstat_async_001', 0, async function (done) {
918
    let fpath = await nextFileName('fileio_lstat_async_001');
919 920 921 922 923 924 925 926 927 928 929 930 931 932
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      fileio.lstat(fpath, function (error) {
        expect(fileio.unlinkSync(fpath) == null).assertTrue();
        done();
      });
    } catch (e) {
      console.log('fileio_lstat_async_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
933
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_0020
934 935
   * @tc.name fileio_lstat_async_002
   * @tc.desc Test Stat.lstatAsync() interface.
936 937 938 939
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
940 941
   */
  it('fileio_lstat_async_002', 0, async function (done) {
942
    let fpath = await nextFileName('fileio_lstat_async_002');
943 944

    try {
945
      fileio.lstat(fpath, function (err) {
946 947 948 949 950 951 952 953 954 955
        done();
      });
    } catch (e) {
      console.log('fileio_lstat_async_002 has failed for ' + e);
      expect(!!e).assertTrue();
      done();
    }
  });

  /**
956
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_DEV_0000
957 958
   * @tc.name fileio_lstat_async_dev_000
   * @tc.desc Test the dev member of class Lstat.
959 960 961 962
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
963 964
   */
  it('fileio_lstat_async_dev_000', 0, async function (done) {
965
    let fpath = await nextFileName('fileio_lstat_async_dev_000');
966 967 968 969 970 971 972 973 974 975 976 977 978 979
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.dev)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_dev_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
980
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_INO_0000
981 982
   * @tc.name fileio_lstat_async_ino_000
   * @tc.desc Test the ino member of class Lstat.
983 984 985 986
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
987 988
   */
  it('fileio_lstat_async_ino_000', 0, async function (done) {
989
    let fpath = await nextFileName('fileio_lstat_async_ino_000');
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.ino)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_ino_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1004
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MODE_0000
1005 1006
   * @tc.name fileio_lstat_async_mode_000
   * @tc.desc Test the mode member of class Lstat.
1007 1008 1009 1010
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1011 1012
   */
  it('fileio_lstat_async_mode_000', 0, async function (done) {
1013
    let fpath = await nextFileName('fileio_lstat_async_mode_000');
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.mode)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_mode_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1028
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_NLINK_0000
1029 1030
   * @tc.name fileio_lstat_async_nlink_000
   * @tc.desc Test the nlink member of class Lstat.
1031 1032 1033 1034
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1035 1036
   */
  it('fileio_lstat_async_nlink_000', 0, async function (done) {
1037
    let fpath = await nextFileName('fileio_lstat_async_nlink_000');
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.nlink)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_nlink_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1052
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_UID_0000
1053 1054
   * @tc.name fileio_lstat_async_uid_000
   * @tc.desc Test the uid member of class Lstat.
1055 1056 1057 1058
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1059 1060
   */
  it('fileio_lstat_async_uid_000', 0, async function (done) {
1061
    let fpath = await nextFileName('fileio_lstat_async_uid_000');
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.uid)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_uid_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1076
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_GID_0000
1077 1078
   * @tc.name fileio_lstat_async_gid_000
   * @tc.desc Test the gid member of class Lstat.
1079 1080 1081 1082
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1083 1084
   */
  it('fileio_lstat_async_gid_000', 0, async function (done) {
1085
    let fpath = await nextFileName('fileio_lstat_async_gid_000');
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.gid)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_gid_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1100
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_RDEV_0000
1101 1102
   * @tc.name fileio_lstat_async_rdev_000
   * @tc.desc Test the rdev member of class Lstat.
1103 1104 1105 1106
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1107 1108
   */
  it('fileio_lstat_async_rdev_000', 0, async function (done) {
1109
    let fpath = await nextFileName('fileio_lstat_async_rdev_000');
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.rdev)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_rdev_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1124
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_SIZE_0000
1125 1126
   * @tc.name fileio_lstat_async_size_000
   * @tc.desc Test the size member of class lstat.
1127 1128 1129 1130
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1131 1132
   */
  it('fileio_lstat_async_size_000', 0, async function (done) {
1133
    let fpath = await nextFileName('fileio_lstat_async_size_000');
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.size)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_size_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1148
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_BLOCKS_0000
1149 1150 1151
   * @tc.name fileio_lstat_async_blocks_000
   * @tc.desc Test lstat.blocks() interface.
   * @tc.desc Test the blocks member of class lstat.
1152 1153 1154 1155
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1156 1157
   */
  it('fileio_lstat_async_blocks_000', 0, async function (done) {
1158
    let fpath = await nextFileName('fileio_lstat_async_blocks_000');
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.blocks)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_blocks_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1173
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_ATIME_0000
1174 1175 1176
   * @tc.name fileio_lstat_async_atime_000
   * @tc.desc Test lstat.atime() interface.
   * @tc.desc Test the atime member of class lstat.
1177 1178 1179 1180
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1181 1182
   */
  it('fileio_lstat_async_atime_000', 0, async function (done) {
1183
    let fpath = await nextFileName('fileio_lstat_async_atime_000');
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.atime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_atime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1198
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_MTIME_0000
1199 1200 1201
   * @tc.name fileio_lstat_async_mtime_000
   * @tc.desc Test lstat.mtime() interface.
   * @tc.desc Test the mtime member of class lstat.
1202 1203 1204 1205
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1206 1207
   */
  it('fileio_lstat_async_mtime_000', 0, async function (done) {
1208
    let fpath = await nextFileName('fileio_lstat_async_mtime_000');
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.mtime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_mtime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1223
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_CTIME_0000
1224 1225
   * @tc.name fileio_lstat_async_ctime_000
   * @tc.desc Test the ctime member of class lstat.
1226 1227 1228 1229
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1230 1231
   */
  it('fileio_lstat_async_ctime_000', 0, async function (done) {
1232
    let fpath = await nextFileName('fileio_lstat_async_ctime_000');
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isIntNum(stat.ctime)).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_ctime_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1247
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0000
1248 1249
   * @tc.name fileio_lstat_async_is_block_device_000
   * @tc.desc Test the isBlockDevice method of class lstat.
1250 1251 1252 1253
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1254 1255
   */
  it('fileio_lstat_async_is_block_device_000', 0, async function (done) {
1256
    let fpath = await nextFileName('fileio_lstat_async_is_block_device_000');
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isBlockDevice())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_block_device_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1271
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_BLOCK_DEVICE_0010
1272 1273
   * @tc.name fileio_lstat_async_is_block_device_001
   * @tc.desc Test the isBlockDevice method of class lstat.
1274 1275 1276 1277
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1278 1279
   */
  it('fileio_lstat_async_is_block_device_001', 0, async function (done) {
1280
    let fpath = await nextFileName('fileio_lstat_async_is_block_device_001');
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isBlockDevice() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_block_device_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1295
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0000
1296 1297
   * @tc.name fileio_lstat_async_is_character_device_000
   * @tc.desc Test the isCharacterDevice method of class lstat.
1298 1299 1300 1301
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1302 1303
   */
  it('fileio_lstat_async_is_character_device_000', 0, async function (done) {
1304
    let fpath = await nextFileName('fileio_lstat_async_is_character_device_000');
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isCharacterDevice())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_character_device_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1319
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_CHARACTER_DEVICE_0010
1320 1321
   * @tc.name fileio_lstat_async_is_character_device_001
   * @tc.desc Test the isCharacterDevice method of class lstat.
1322 1323 1324 1325
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1326 1327
   */
  it('fileio_lstat_async_is_character_device_001', 0, async function (done) {
1328
    let fpath = await nextFileName('fileio_lstat_async_is_character_device_001');
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isCharacterDevice() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_character_device_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1343
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0000
1344 1345
   * @tc.name fileio_lstat_async_is_directory_000
   * @tc.desc Test lstat.isDirectory() interface.
1346 1347 1348 1349
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1350 1351
   */
  it('fileio_lstat_async_is_directory_000', 0, async function (done) {
1352
    let fpath = await nextFileName('fileio_lstat_async_is_directory_000');
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isDirectory())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_directory_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1367
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0010
1368 1369
   * @tc.name fileio_lstat_async_is_directory_001
   * @tc.desc Test lstat.isDirectory() interface.
1370 1371 1372 1373
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1374 1375
   */
  it('fileio_lstat_async_is_directory_001', 0, async function (done) {
1376
    let fpath = await nextFileName('fileio_lstat_async_is_directory_001');
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isDirectory() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_directory_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1391
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_DIRECTORY_0020
1392 1393
   * @tc.name fileio_lstat_async_is_directory_002
   * @tc.desc Test lstat.isDirectory() interface.
1394 1395 1396 1397
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1398 1399
   */
  it('fileio_lstat_async_is_directory_002', 0, async function (done) {
1400
    let dpath = await nextFileName('fileio_lstat_async_is_directory_002') + 'd';
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = await fileio.lstat(dpath);
      expect(stat.isDirectory()).assertTrue();
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_directory_002 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1415
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0000
1416 1417
   * @tc.name fileio_lstat_async_is_fifo_000
   * @tc.desc Test lstat.isFIFO() interface.
1418 1419 1420 1421
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1422 1423
   */
  it('fileio_lstat_async_is_fifo_000', 0, async function (done) {
1424
    let fpath = await nextFileName('fileio_lstat_async_is_fifo_000');
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isFIFO())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_fifo_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1439
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FIFO_0010
1440 1441
   * @tc.name fileio_lstat_async_is_fifo_001
   * @tc.desc Test lstat.isFIFO() interface.
1442 1443 1444 1445
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1446 1447
   */
  it('fileio_lstat_async_is_fifo_001', 0, async function (done) {
1448
    let fpath = await nextFileName('fileio_lstat_async_is_fifo_001');
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isFIFO() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_fifo_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1463
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0000
1464 1465
   * @tc.name fileio_lstat_async_is_file_000
   * @tc.desc Test lstat.isFile() interface.
1466 1467 1468 1469
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1470 1471
   */
  it('fileio_lstat_async_is_file_000', 0, async function (done) {
1472
    let fpath = await nextFileName('fileio_lstat_async_is_file_000');
R
raoxian 已提交
1473
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isFile())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_file_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1487
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0010
1488 1489
   * @tc.name fileio_lstat_async_is_file_001
   * @tc.desc Test lstat.isFile() interface.
1490 1491 1492 1493
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1494 1495
   */
  it('fileio_lstat_async_is_file_001', 0, async function (done) {
1496
    let fpath = await nextFileName('fileio_lstat_async_is_file_001');
R
raoxian 已提交
1497
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isFile()).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_file_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1511
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_FILE_0020
1512 1513
   * @tc.name fileio_lstat_async_is_file_002
   * @tc.desc Test lstat.isFile() interface.
1514 1515 1516 1517
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1518 1519
   */
  it('fileio_lstat_async_is_file_002', 0, async function (done) {
1520
    let dpath = await nextFileName('fileio_lstat_async_is_file_002');
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534

    try {
      expect(fileio.mkdirSync(dpath) == null).assertTrue();
      let stat = await fileio.lstat(dpath);
      expect(stat.isFile() === false).assertTrue();
      expect(fileio.rmdirSync(dpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_file_002 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1535
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0000
1536 1537
   * @tc.name fileio_lstat_async_is_socket_000
   * @tc.desc Test lstat.isSocket() interface.
1538 1539 1540 1541
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1542 1543
   */
  it('fileio_lstat_async_is_socket_000', 0, async function (done) {
1544
    let fpath = await nextFileName('fileio_lstat_async_is_socket_000');
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isSocket())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_socket_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1559
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SOCKET_0010
1560 1561
   * @tc.name fileio_lstat_async_is_socket_001
   * @tc.desc Test lstat.isSocket() interface.
1562 1563 1564 1565
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1566 1567
   */
  it('fileio_lstat_async_is_socket_001', 0, async function (done) {
1568
    let fpath = await nextFileName('fileio_lstat_async_is_socket_001');
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isSocket() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_socket_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1583
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0000
1584 1585
   * @tc.name fileio_lstat_async_is_symbolic_link_000
   * @tc.desc Test lstat.isSymbolicLink() interface.
1586 1587 1588 1589
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1590 1591
   */
  it('fileio_lstat_async_is_symbolic_link_000', 0, async function (done) {
1592
    let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_000');
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(isBoolean(stat.isSymbolicLink())).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_symbolic_link_000 has failed for ' + e);
      expect(null).assertFail();
    }
  });

  /**
1607
   * @tc.number SUB_DF_FILEIO_LSTAT_ASYNC_IS_SYMBOLIC_LINK_0010
1608 1609
   * @tc.name fileio_lstat_async_is_symbolic_link_001
   * @tc.desc Test lstat.isSymbolicLink() interface.
1610 1611 1612 1613
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
1614 1615
   */
  it('fileio_lstat_async_is_symbolic_link_001', 0, async function (done) {
1616
    let fpath = await nextFileName('fileio_lstat_async_is_symbolic_link_001');
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = await fileio.lstat(fpath);
      expect(stat.isSymbolicLink() === false).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
      done();
    } catch (e) {
      console.log('fileio_lstat_async_is_symbolic_link_001 has failed for ' + e);
      expect(null).assertFail();
    }
  });

1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
  /**
   * @tc.number SUB_DF_FILEIO_APPEND_FILE_SYNC_0010
   * @tc.name fileio_test_append_file_sync_000
   * @tc.desc Test lstat.lstatSync() interface.
   * @tc.size MEDIUM
   * @tc.type Function
   * @tc.level Level 0
   * @tc.require
   */
  it('fileio_test_append_file_sync_000', 0, async function (done) {
    let fpath = await nextFileName('fileio_test_append_file_sync_000');
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
    expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();

    try {
      let stat = fileio.lstatSync(fpath);
      expect(isIntNum(stat.size)).assertTrue();

      let fd = fileio.openSync(fpath, 0o2002);
      expect(isIntNum(fd)).assertTrue();

      expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
      expect(fileio.closeSync(fd) == null).assertTrue();

      stat = fileio.lstatSync(fpath);
      expect(stat.size == FILE_CONTENT.length * 2).assertTrue();
      expect(fileio.unlinkSync(fpath) == null).assertTrue();
    } catch (e) {
      console.log('fileio_test_append_file_sync_000 has failed for ' + e);
      expect(null).assertFail();
    }
    done();
  });
});