Index: test_utils.h |
diff --git a/test_utils.h b/test_utils.h |
index 4c8288892b37eb82dd4e904d0f40b62965efa8ee..889d579e5764415b924b660c84cf60e4cfde943a 100644 |
--- a/test_utils.h |
+++ b/test_utils.h |
@@ -10,6 +10,7 @@ |
#include <vector> |
#include <gtest/gtest.h> |
#include "base/scoped_ptr.h" |
+#include "base/string_util.h" |
petkov
2010/12/10 00:46:55
since you've touched the headers -- "new" style is
thieule
2010/12/14 23:11:21
Done.
|
#include "update_engine/action.h" |
#include "update_engine/subprocess.h" |
#include "update_engine/utils.h" |
@@ -92,6 +93,11 @@ const unsigned char kRandomString[] = { |
const char* const kMountPath = "/tmp/UpdateEngineTests_mnt"; |
} // namespace {} |
+// Creates an empty ext image. |
petkov
2010/12/10 00:46:55
ext2, ext3, ext4?
thieule
2010/12/14 23:11:21
This is a little bit more involved than just here.
|
+void CreateEmptyExtImageAtPath(const std::string& path, |
+ size_t size, |
+ int block_size); |
+ |
// Creates an ext image with some files in it. The paths creates are |
// returned in out_paths. |
void CreateExtImageAtPath(const std::string& path, |
@@ -211,6 +217,28 @@ struct ObjectCollectorAction : public Action<ObjectCollectorAction<T> > { |
T object_; |
}; |
+class ScopedLoopMounter { |
+ public: |
+ explicit ScopedLoopMounter(const std::string& file_path, |
+ std::string* mnt_path, |
+ unsigned long flags) { |
+ EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path)); |
petkov
2010/12/10 00:46:55
lots of code for a header file. could you please m
thieule
2010/12/14 23:11:21
Done.
|
+ dir_remover_.reset(new ScopedDirRemover(*mnt_path)); |
+ |
+ std::string loop_dev = GetUnusedLoopDevice(); |
+ EXPECT_EQ(0, system(StringPrintf("losetup %s %s", loop_dev.c_str(), |
+ file_path.c_str()).c_str())); |
+ loop_releaser_.reset(new ScopedLoopbackDeviceReleaser(loop_dev)); |
+ |
+ EXPECT_TRUE(utils::MountFilesystem(loop_dev, *mnt_path, flags)); |
+ unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path)); |
+ } |
+ private: |
petkov
2010/12/10 00:46:55
blank line before private
thieule
2010/12/14 23:11:21
Done.
|
+ scoped_ptr<ScopedDirRemover> dir_remover_; |
petkov
2010/12/10 00:46:55
i guess this is not new code but... is there any r
thieule
2010/12/14 23:11:21
There is an explicit order that these objects must
|
+ scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; |
+ scoped_ptr<ScopedFilesystemUnmounter> unmounter_; |
+}; |
+ |
} // namespace chromeos_update_engine |
#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |