Home | History | Annotate | Download | only in media_galleries
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/media_galleries/picasa_test_util.h"
      6 
      7 #include "base/files/file_path.h"
      8 #include "base/files/file_util.h"
      9 #include "chrome/common/media_galleries/picasa_types.h"
     10 #include "chrome/common/media_galleries/pmp_test_util.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 
     13 namespace picasa {
     14 
     15 void WriteAlbumTable(const base::FilePath& column_file_destination,
     16                      const std::vector<uint32>& category_vector,
     17                      const std::vector<double>& date_vector,
     18                      const std::vector<std::string>& filename_vector,
     19                      const std::vector<std::string>& name_vector,
     20                      const std::vector<std::string>& token_vector,
     21                      const std::vector<std::string>& uid_vector) {
     22   ASSERT_TRUE(PmpTestUtil::WriteIndicatorFile(
     23       column_file_destination, kPicasaAlbumTableName));
     24   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     25       column_file_destination, kPicasaAlbumTableName, "category",
     26       PMP_TYPE_UINT32, category_vector));
     27   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     28       column_file_destination, kPicasaAlbumTableName, "date",
     29       PMP_TYPE_DOUBLE64, date_vector));
     30   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     31       column_file_destination, kPicasaAlbumTableName, "filename",
     32       PMP_TYPE_STRING, filename_vector));
     33   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     34       column_file_destination, kPicasaAlbumTableName, "name",
     35       PMP_TYPE_STRING, name_vector));
     36   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     37       column_file_destination, kPicasaAlbumTableName, "token",
     38       PMP_TYPE_STRING, token_vector));
     39   ASSERT_TRUE(PmpTestUtil::WriteColumnFileFromVector(
     40       column_file_destination, kPicasaAlbumTableName, "uid",
     41       PMP_TYPE_STRING, uid_vector));
     42 }
     43 
     44 void WriteTestAlbumTable(
     45     const base::FilePath& column_file_destination,
     46     const base::FilePath& test_folder_1_path,
     47     const base::FilePath& test_folder_2_path) {
     48   std::vector<uint32> category_vector;
     49   category_vector.push_back(kAlbumCategoryFolder);
     50   category_vector.push_back(kAlbumCategoryInvalid);
     51   category_vector.push_back(kAlbumCategoryAlbum);
     52   category_vector.push_back(kAlbumCategoryFolder);
     53   category_vector.push_back(kAlbumCategoryAlbum);
     54 
     55   std::vector<double> date_vector;
     56   date_vector.push_back(0.0);
     57   date_vector.push_back(0.0);
     58   date_vector.push_back(0.0);
     59   date_vector.push_back(0.0);
     60   date_vector.push_back(0.0);
     61 
     62   std::vector<std::string> filename_vector;
     63   filename_vector.push_back(test_folder_1_path.AsUTF8Unsafe());
     64   filename_vector.push_back("");
     65   filename_vector.push_back("");
     66   filename_vector.push_back(test_folder_2_path.AsUTF8Unsafe());
     67   filename_vector.push_back("");
     68 
     69   std::vector<std::string> name_vector;
     70   name_vector.push_back(test_folder_1_path.BaseName().AsUTF8Unsafe());
     71   name_vector.push_back("");
     72   name_vector.push_back("Album 1 Name");
     73   name_vector.push_back(test_folder_2_path.BaseName().AsUTF8Unsafe());
     74   name_vector.push_back("Album 2 Name");
     75 
     76   std::vector<std::string> token_vector;
     77   token_vector.push_back("");
     78   token_vector.push_back("");
     79   token_vector.push_back(std::string(kAlbumTokenPrefix) + "uid3");
     80   token_vector.push_back("");
     81   token_vector.push_back(std::string(kAlbumTokenPrefix) + "uid5");
     82 
     83   std::vector<std::string> uid_vector;
     84   uid_vector.push_back("uid1");
     85   uid_vector.push_back("uid2");
     86   uid_vector.push_back("uid3");
     87   uid_vector.push_back("uid4");
     88   uid_vector.push_back("uid5");
     89 
     90   WriteAlbumTable(column_file_destination, category_vector, date_vector,
     91                   filename_vector, name_vector, token_vector, uid_vector);
     92 }
     93 
     94 void WriteTestAlbumsImagesIndex(const base::FilePath& test_folder_1_path,
     95                                 const base::FilePath& test_folder_2_path) {
     96   const char folder_1_test_ini[] =
     97       "[InBoth.jpg]\n"
     98       "albums=uid3,uid5\n"
     99       "[InSecondAlbumOnly.jpg]\n"
    100       "albums=uid5\n";
    101   ASSERT_TRUE(
    102       base::WriteFile(test_folder_1_path.AppendASCII(kPicasaINIFilename),
    103                       folder_1_test_ini,
    104                       arraysize(folder_1_test_ini)));
    105 
    106   const char folder_2_test_ini[] =
    107       "[InFirstAlbumOnly.jpg]\n"
    108       "albums=uid3\n";
    109   ASSERT_TRUE(
    110       base::WriteFile(test_folder_2_path.AppendASCII(kPicasaINIFilename),
    111                       folder_2_test_ini,
    112                       arraysize(folder_2_test_ini)));
    113 }
    114 
    115 }  // namespace picasa
    116