Skip to content
This repository
Browse code

Add test case for normal RAR with directories and symlinks.

  • Loading branch information...
commit 9c141d0708ed257cfb0df5bfeae9d6dab557cf81 1 parent 7efb0d7
Andres Mejia authored January 19, 2013
222  xbmc/filesystem/test/TestRarFile.cpp
@@ -415,4 +415,226 @@ TEST(TestRarFile, StoredRAR)
415 415
   EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
416 416
   file.Close();
417 417
 }
  418
+
  419
+TEST(TestRarFile, NormalRAR)
  420
+{
  421
+  XFILE::CFile file;
  422
+  char buf[20];
  423
+  memset(&buf, 0, sizeof(buf));
  424
+  CStdString reffile, strrarpath, strpathinrar;
  425
+  CFileItemList itemlist, itemlistemptydir;
  426
+  struct __stat64 stat_buffer;
  427
+
  428
+  reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/refRARnormal.rar");
  429
+  URIUtils::CreateArchivePath(strrarpath, "rar", reffile, "");
  430
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strrarpath, itemlist));
  431
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  432
+
  433
+  /* /reffile.txt */
  434
+  strpathinrar = itemlist[1]->GetPath();
  435
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/reffile.txt", true));
  436
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  437
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  438
+
  439
+  ASSERT_TRUE(file.Open(strpathinrar));
  440
+  EXPECT_EQ(0, file.GetPosition());
  441
+  EXPECT_EQ(1616, file.GetLength());
  442
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  443
+  file.Flush();
  444
+  EXPECT_EQ(20, file.GetPosition());
  445
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  446
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  447
+  EXPECT_EQ(39, file.GetPosition());
  448
+  EXPECT_STREQ("an award-winning fr", buf);
  449
+  EXPECT_EQ(100, file.Seek(100));
  450
+  EXPECT_EQ(100, file.GetPosition());
  451
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  452
+  file.Flush();
  453
+  EXPECT_EQ(120, file.GetPosition());
  454
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  455
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  456
+  EXPECT_EQ(220, file.GetPosition());
  457
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  458
+  file.Flush();
  459
+  EXPECT_EQ(240, file.GetPosition());
  460
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  461
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  462
+  EXPECT_EQ(1596, file.GetPosition());
  463
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  464
+  file.Flush();
  465
+  EXPECT_EQ(1616, file.GetPosition());
  466
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  467
+  EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
  468
+  EXPECT_EQ(1716, file.GetPosition());
  469
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  470
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  471
+  file.Flush();
  472
+  EXPECT_EQ(20, file.GetPosition());
  473
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  474
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  475
+  EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
  476
+  file.Close();
  477
+
  478
+  /* /testsymlink -> testdir/reffile.txt */
  479
+  strpathinrar = itemlist[2]->GetPath();
  480
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlink", true));
  481
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  482
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  483
+
  484
+  /*
  485
+   * FIXME: Reading symlinks in RARs is currently broken. It takes a long time
  486
+   * to read them and they produce erroneous results. The expected result is
  487
+   * the target paths of the symlinks.
  488
+   */
  489
+  ASSERT_TRUE(file.Open(strpathinrar));
  490
+  EXPECT_EQ(19, file.GetLength());
  491
+  file.Close();
  492
+
  493
+  /* /testsymlinksubdir -> testdir/testsubdir/reffile.txt */
  494
+  strpathinrar = itemlist[3]->GetPath();
  495
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlinksubdir", true));
  496
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  497
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  498
+
  499
+  ASSERT_TRUE(file.Open(strpathinrar));
  500
+  EXPECT_EQ(30, file.GetLength());
  501
+  file.Close();
  502
+
  503
+  /* /testdir/ */
  504
+  strpathinrar = itemlist[0]->GetPath();
  505
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/", true));
  506
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  507
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  508
+
  509
+  itemlist.Clear();
  510
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
  511
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  512
+
  513
+  /* /testdir/reffile.txt */
  514
+  strpathinrar = itemlist[1]->GetPath();
  515
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/reffile.txt",
  516
+                                    true));
  517
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  518
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  519
+
  520
+  ASSERT_TRUE(file.Open(strpathinrar));
  521
+  EXPECT_EQ(0, file.GetPosition());
  522
+  EXPECT_EQ(1616, file.GetLength());
  523
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  524
+  file.Flush();
  525
+  EXPECT_EQ(20, file.GetPosition());
  526
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  527
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  528
+  EXPECT_EQ(39, file.GetPosition());
  529
+  EXPECT_STREQ("an award-winning fr", buf);
  530
+  EXPECT_EQ(100, file.Seek(100));
  531
+  EXPECT_EQ(100, file.GetPosition());
  532
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  533
+  file.Flush();
  534
+  EXPECT_EQ(120, file.GetPosition());
  535
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  536
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  537
+  EXPECT_EQ(220, file.GetPosition());
  538
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  539
+  file.Flush();
  540
+  EXPECT_EQ(240, file.GetPosition());
  541
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  542
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  543
+  EXPECT_EQ(1596, file.GetPosition());
  544
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  545
+  file.Flush();
  546
+  EXPECT_EQ(1616, file.GetPosition());
  547
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  548
+  EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
  549
+  EXPECT_EQ(1716, file.GetPosition());
  550
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  551
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  552
+  file.Flush();
  553
+  EXPECT_EQ(20, file.GetPosition());
  554
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  555
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  556
+  EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
  557
+  file.Close();
  558
+
  559
+  /* /testdir/testemptysubdir */
  560
+  strpathinrar = itemlist[2]->GetPath();
  561
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testemptysubdir",
  562
+                                    true));
  563
+  /* TODO: Should this set the itemlist to an empty list instead? */
  564
+  EXPECT_FALSE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlistemptydir));
  565
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  566
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  567
+
  568
+  /* FIXME: This directory appears a second time as a file */
  569
+  strpathinrar = itemlist[3]->GetPath();
  570
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir", true));
  571
+
  572
+  /* /testdir/testsymlink -> testsubdir/reffile.txt */
  573
+  strpathinrar = itemlist[4]->GetPath();
  574
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsymlink",
  575
+                                    true));
  576
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  577
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  578
+
  579
+  ASSERT_TRUE(file.Open(strpathinrar));
  580
+  EXPECT_EQ(22, file.GetLength());
  581
+  file.Close();
  582
+
  583
+  /* /testdir/testsubdir/ */
  584
+  strpathinrar = itemlist[0]->GetPath();
  585
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir/",
  586
+                                    true));
  587
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  588
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  589
+
  590
+  itemlist.Clear();
  591
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
  592
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  593
+
  594
+  /* /testdir/testsubdir/reffile.txt */
  595
+  strpathinrar = itemlist[0]->GetPath();
  596
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar,
  597
+                                    "/testdir/testsubdir/reffile.txt", true));
  598
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  599
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  600
+
  601
+  ASSERT_TRUE(file.Open(strpathinrar));
  602
+  EXPECT_EQ(0, file.GetPosition());
  603
+  EXPECT_EQ(1616, file.GetLength());
  604
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  605
+  file.Flush();
  606
+  EXPECT_EQ(20, file.GetPosition());
  607
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  608
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  609
+  EXPECT_EQ(39, file.GetPosition());
  610
+  EXPECT_STREQ("an award-winning fr", buf);
  611
+  EXPECT_EQ(100, file.Seek(100));
  612
+  EXPECT_EQ(100, file.GetPosition());
  613
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  614
+  file.Flush();
  615
+  EXPECT_EQ(120, file.GetPosition());
  616
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  617
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  618
+  EXPECT_EQ(220, file.GetPosition());
  619
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  620
+  file.Flush();
  621
+  EXPECT_EQ(240, file.GetPosition());
  622
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  623
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  624
+  EXPECT_EQ(1596, file.GetPosition());
  625
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  626
+  file.Flush();
  627
+  EXPECT_EQ(1616, file.GetPosition());
  628
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  629
+  EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
  630
+  EXPECT_EQ(1716, file.GetPosition());
  631
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  632
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  633
+  file.Flush();
  634
+  EXPECT_EQ(20, file.GetPosition());
  635
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  636
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  637
+  EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
  638
+  file.Close();
  639
+}
418 640
 #endif /*HAS_FILESYSTEM_RAR*/
BIN  xbmc/filesystem/test/refRARnormal.rar
Binary file not shown

0 notes on commit 9c141d0

Please sign in to comment.
Something went wrong with that request. Please try again.