Esempio n. 1
0
        public void TestDuplicates()
        {
            testName = "TestDuplicates";
            SetUpTest(true);
            string dbFileName    = testHome + "/" + testName + ".db";
            string dbSecFileName = testHome + "/" + testName
                                   + "_sec.db";

            // Open a primary hash database.
            HashDatabaseConfig dbConfig =
                new HashDatabaseConfig();

            dbConfig.Creation = CreatePolicy.ALWAYS;
            HashDatabase db = HashDatabase.Open(
                dbFileName, dbConfig);

            // Open a secondary hash database.
            SecondaryHashDatabaseConfig secConfig =
                new SecondaryHashDatabaseConfig(null, null);

            secConfig.Primary    = db;
            secConfig.Duplicates = DuplicatesPolicy.SORTED;
            secConfig.Creation   = CreatePolicy.IF_NEEDED;
            SecondaryHashDatabase secDB =
                SecondaryHashDatabase.Open(
                    dbSecFileName, secConfig);

            // Confirm the duplicate in opened secondary database.
            Assert.AreEqual(DuplicatesPolicy.SORTED,
                            secDB.Duplicates);

            secDB.Close();
            db.Close();
        }
        public void TestHashFunction()
        {
            testName = "TestHashFunction";
            testHome = testFixtureHome + "/" + testName;
            string dbFileName    = testHome + "/" + testName + ".db";
            string dbSecFileName = testHome + "/" +
                                   testName + "_sec.db";

            Configuration.ClearDir(testHome);

            // Open a primary hash database.
            HashDatabaseConfig dbConfig =
                new HashDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            HashDatabase hashDB = HashDatabase.Open(
                dbFileName, dbConfig);

            /*
             * Define hash function and open a secondary
             * hash database.
             */
            SecondaryHashDatabaseConfig secDBConfig =
                new SecondaryHashDatabaseConfig(hashDB, null);

            secDBConfig.HashFunction =
                new HashFunctionDelegate(HashFunction);
            secDBConfig.Creation = CreatePolicy.IF_NEEDED;
            SecondaryHashDatabase secDB =
                SecondaryHashDatabase.Open(dbSecFileName,
                                           secDBConfig);

            /*
             * Confirm the hash function defined in the configuration.
             * Call the hash function and the one from secondary
             * database. If they return the same value, then the hash
             * function is configured successfully.
             */
            uint data = secDB.HashFunction(BitConverter.GetBytes(1));

            Assert.AreEqual(0, data);

            // Close all.
            secDB.Close();
            hashDB.Close();
        }
        public void TestCompare()
        {
            testName = "TestCompare";
            testHome = testFixtureHome + "/" + testName;
            string dbFileName    = testHome + "/" + testName + ".db";
            string dbSecFileName = testHome + "/" + testName +
                                   "_sec.db";

            Configuration.ClearDir(testHome);

            // Open a primary hash database.
            HashDatabaseConfig dbConfig =
                new HashDatabaseConfig();

            dbConfig.Creation = CreatePolicy.ALWAYS;
            HashDatabase db = HashDatabase.Open(
                dbFileName, dbConfig);

            // Open a secondary hash database.
            SecondaryHashDatabaseConfig secConfig =
                new SecondaryHashDatabaseConfig(null, null);

            secConfig.Creation = CreatePolicy.IF_NEEDED;
            secConfig.Primary  = db;
            secConfig.Compare  =
                new EntryComparisonDelegate(SecondaryEntryComparison);
            SecondaryHashDatabase secDB =
                SecondaryHashDatabase.Open(dbSecFileName, secConfig);

            /*
             * Get the compare function set in the configuration
             * and run it in a comparison to see if it is alright.
             */
            DatabaseEntry dbt1, dbt2;

            dbt1 = new DatabaseEntry(
                BitConverter.GetBytes((int)257));
            dbt2 = new DatabaseEntry(
                BitConverter.GetBytes((int)255));
            Assert.Less(0, secDB.Compare(dbt1, dbt2));

            secDB.Close();
            db.Close();
        }