storage/test/test_file_perms.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/storage/test/test_file_perms.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "storage_test_harness.h"
    1.11 +#include "nsIFile.h"
    1.12 +#include "prio.h"
    1.13 +
    1.14 +/**
    1.15 + * This file tests that the file permissions of the sqlite files match what
    1.16 + * we request they be
    1.17 + */
    1.18 +
    1.19 +void
    1.20 +test_file_perms()
    1.21 +{
    1.22 +  nsCOMPtr<mozIStorageConnection> db(getDatabase());
    1.23 +  nsCOMPtr<nsIFile> dbFile;
    1.24 +  do_check_success(db->GetDatabaseFile(getter_AddRefs(dbFile)));
    1.25 +
    1.26 +  uint32_t perms = 0;
    1.27 +  do_check_success(dbFile->GetPermissions(&perms));
    1.28 +
    1.29 +  // This reflexts the permissions defined by SQLITE_DEFAULT_FILE_PERMISSIONS in
    1.30 +  // db/sqlite3/src/Makefile.in and must be kept in sync with that
    1.31 +#ifdef ANDROID
    1.32 +  do_check_true(perms == (PR_IRUSR | PR_IWUSR));
    1.33 +#elif defined(XP_WIN)
    1.34 +  do_check_true(perms == (PR_IRUSR | PR_IWUSR | PR_IRGRP | PR_IWGRP | PR_IROTH | PR_IWOTH));
    1.35 +#else
    1.36 +  do_check_true(perms == (PR_IRUSR | PR_IWUSR | PR_IRGRP | PR_IROTH));
    1.37 +#endif
    1.38 +}
    1.39 +
    1.40 +void (*gTests[])(void) = {
    1.41 +  test_file_perms,
    1.42 +};
    1.43 +
    1.44 +const char *file = __FILE__;
    1.45 +#define TEST_NAME "file perms"
    1.46 +#define TEST_FILE file
    1.47 +#include "storage_test_harness_tail.h"

mercurial