Example #1
0
        public override void Initialize()
        {
            CheckDisposed();
            base.Initialize();

            // This is a bit odd, but because of the unpredictable timing of garbage collection,
            // it's possible for the junk file to be deleted by the GC from a previous test,
            // resulting in a FileNotFoundException in the CmPicture constructor. So we
            // just give it a few shots at it to make it more reliable.
            bool fSucceeded = false;

            for (int i = 0; i < 5 && !fSucceeded; i++)
            {
                try
                {
                    using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
                    {
                        m_pict = new CmPicture(Cache, filemaker.Filename,
                                               m_factory.MakeString("Test picture", Cache.DefaultVernWs),
                                               StringUtils.LocalPictures);
                        fSucceeded = true;
                    }
                }
                catch (FileNotFoundException)
                {
                }
            }
            Assert.IsNotNull(m_pict);
            m_internalPath = m_pict.PictureFileRA.InternalPath;
            Assert.IsNotNull(m_internalPath, "Internal path not set correctly");
            Assert.IsTrue(m_pict.PictureFileRA.AbsoluteInternalPath == m_internalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
            m_internalFilesToDelete.Add(m_pict.PictureFileRA.AbsoluteInternalPath);
        }
        public void CreateNewLangProject_DbFilesExist()
        {
            DummyFwNewLangProjectCreator creator = new DummyFwNewLangProjectCreator();

            // Setup: Create "pre-existing" DB filenames
            using (
                DummyFileMaker existingDB =
                    new DummyFileMaker(DirectoryFinder.DataDirectory + @"\Gumby.mdf"),
                existingDB2 =
                    new DummyFileMaker(DirectoryFinder.DataDirectory + @"\Gumby2.mdf"),
                existingLogFile =
                    new DummyFileMaker(DirectoryFinder.DataDirectory + @"\Gumby_log.ldf"),
                existingLogFile1 =
                    new DummyFileMaker(DirectoryFinder.DataDirectory + @"\Gumby1_log.ldf"))
            {
                List <string> preExistingFiles =
                    new List <string>(Directory.GetFiles(DirectoryFinder.DataDirectory));
                List <string> postExistingFiles = null;

                try
                {
                    string sNewDbFileName;
                    string sNewLogFileName;
                    creator.CallCreateNewDbFiles("Gumby", out sNewDbFileName, out sNewLogFileName);

                    postExistingFiles =
                        new List <string>(Directory.GetFiles(DirectoryFinder.DataDirectory));

                    Assert.AreEqual(DirectoryFinder.DataDirectory + @"\Gumby3.mdf", sNewDbFileName);
                    Assert.AreEqual(DirectoryFinder.DataDirectory + @"\Gumby3_log.ldf", sNewLogFileName);

                    Assert.IsTrue(File.Exists(sNewDbFileName));
                    Assert.IsTrue(File.Exists(sNewLogFileName));
                    Assert.AreEqual(preExistingFiles.Count + 2, postExistingFiles.Count);
                }
                finally
                {
                    // Blow away the files to clean things up
                    if (postExistingFiles == null)
                    {
                        postExistingFiles =
                            new List <string>(Directory.GetFiles(DirectoryFinder.DataDirectory));
                    }
                    foreach (string fileName in postExistingFiles)
                    {
                        try
                        {
                            if (!preExistingFiles.Contains(fileName))
                            {
                                File.Delete(fileName);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
Example #3
0
        public void TestTextRepOfObj_CmPicture()
        {
            CheckDisposed();

            string internalPathOrig = null;
            string internalPathNew  = null;

            try
            {
                using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
                {
                    ITsStrFactory factory    = TsStrFactoryClass.Create();
                    EditingHelper editHelper = new EditingHelper(null);
                    CmPicture     pict       = new CmPicture(m_fdoCache, filemaker.Filename,
                                                             factory.MakeString("Test picture", m_fdoCache.DefaultVernWs),
                                                             StringUtils.LocalPictures);
                    Assert.IsNotNull(pict);
                    Assert.IsTrue(pict.PictureFileRA.AbsoluteInternalPath == pict.PictureFileRA.InternalPath);
                    Guid   guid             = Cache.GetGuidFromId(pict.Hvo);
                    string sTextRepOfObject = editHelper.TextRepOfObj(m_fdoCache, guid);
                    int    objectDataType;
                    guid = editHelper.MakeObjFromText(m_fdoCache, sTextRepOfObject, null,
                                                      out objectDataType);
                    CmPicture pictNew = new CmPicture(Cache, Cache.GetIdFromGuid(guid));
                    Assert.IsTrue(pict != pictNew);
                    internalPathOrig = pict.PictureFileRA.AbsoluteInternalPath;
                    internalPathNew  = pictNew.PictureFileRA.AbsoluteInternalPath;
                    Assert.AreEqual(internalPathOrig, internalPathNew);
                    Assert.AreEqual(internalPathOrig.IndexOf("junk"), internalPathNew.IndexOf("junk"));
                    Assert.IsTrue(internalPathNew.EndsWith(".jpg"));
                    AssertEx.AreTsStringsEqual(pict.Caption.VernacularDefaultWritingSystem.UnderlyingTsString,
                                               pictNew.Caption.VernacularDefaultWritingSystem.UnderlyingTsString);
                    Assert.AreEqual(pict.PictureFileRA.OwnerHVO, pictNew.PictureFileRA.OwnerHVO);
                }
            }
            finally
            {
                // TODO: When Undo works right, these should get cleaned up automatically
                if (internalPathOrig != null)
                {
                    File.Delete(internalPathOrig);
                }
                if (internalPathNew != null)
                {
                    File.Delete(internalPathNew);
                }
            }
        }
        public void TestTextRepOfObj_CmPicture()
        {
            string internalPathOrig = null;
            string internalPathNew  = null;

            try
            {
                using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
                {
                    ITsStrFactory factory = TsStrFactoryClass.Create();
                    using (var editHelper = new RootSiteEditingHelper(Cache, null))
                    {
                        ICmPicture pict = Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create(
                            filemaker.Filename, factory.MakeString("Test picture", Cache.DefaultVernWs),
                            CmFolderTags.LocalPictures);
                        Assert.IsNotNull(pict);
                        Assert.IsTrue(pict.PictureFileRA.AbsoluteInternalPath == pict.PictureFileRA.InternalPath);
                        string sTextRepOfObject = editHelper.TextRepOfObj(Cache, pict.Guid);
                        int    objectDataType;
                        Guid   guid = editHelper.MakeObjFromText(Cache, sTextRepOfObject, null,
                                                                 out objectDataType);
                        ICmPicture pictNew = Cache.ServiceLocator.GetInstance <ICmPictureRepository>().GetObject(guid);
                        Assert.IsTrue(pict != pictNew);
                        internalPathOrig = pict.PictureFileRA.AbsoluteInternalPath;
                        internalPathNew  = pictNew.PictureFileRA.AbsoluteInternalPath;
                        Assert.AreEqual(internalPathOrig, internalPathNew);
                        Assert.AreEqual(internalPathOrig.IndexOf("junk"), internalPathNew.IndexOf("junk"));
                        Assert.IsTrue(internalPathNew.EndsWith(".jpg"));
                        AssertEx.AreTsStringsEqual(pict.Caption.VernacularDefaultWritingSystem,
                                                   pictNew.Caption.VernacularDefaultWritingSystem);
                        Assert.AreEqual(pict.PictureFileRA.Owner, pictNew.PictureFileRA.Owner);
                    }
                }
            }
            finally
            {
                // TODO: When Undo works right, these should get cleaned up automatically
                if (internalPathOrig != null)
                {
                    File.Delete(internalPathOrig);
                }
                if (internalPathNew != null)
                {
                    File.Delete(internalPathNew);
                }
            }
        }
Example #5
0
        public void UpdateCmPicture()
        {
            CheckDisposed();

            using (DummyFileMaker fileMaker = new DummyFileMaker("junk1.gif", true))
            {
                ((CmPicture)m_pict).UpdatePicture(fileMaker.Filename,
                                                  m_factory.MakeString("Updated Picture", Cache.DefaultVernWs), StringUtils.LocalPictures);
                Assert.AreEqual("Updated Picture", m_pict.Caption.VernacularDefaultWritingSystem.Text);
                string internalPathUpdated = m_pict.PictureFileRA.InternalPath;
                Assert.IsNotNull(internalPathUpdated, "Internal path not set correctly");
                Assert.IsTrue(m_pict.PictureFileRA.AbsoluteInternalPath == internalPathUpdated, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
                m_internalFilesToDelete.Add(m_pict.PictureFileRA.AbsoluteInternalPath);
                int ich = internalPathUpdated.IndexOf("junk1");
                Assert.IsTrue(ich > 0);
                Assert.IsTrue(internalPathUpdated.EndsWith(".gif"));
            }
        }
Example #6
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("junk56.jpg", true))
            {
                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.IsNotNull(file, "null CmFile returned");
                Assert.IsNotNull(file.InternalPath, "Internal path not set correctly");
                Assert.IsTrue(file.AbsoluteInternalPath == file.InternalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
                m_internalFilesToDelete.Add(file.AbsoluteInternalPath);
                Assert.IsTrue(m_pict.PictureFileRAHvo != file.Hvo);
            }
        }
Example #7
0
        public void CmFileFinder_OrigFilesMatch()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("garbage.jpg", true))
            {
                ICmFile fileOrig = new CmFile();
                folder.FilesOC.Add(fileOrig);
                fileOrig.InternalPath = maker.Filename;

                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.AreEqual(fileOrig, file);
            }
        }
Example #8
0
        public void CreateOwnedObjects_Picture()
        {
            CheckDisposed();

            StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0];

            ITsString     tss     = para.Contents.UnderlyingTsString;
            ITsStrFactory factory = TsStrFactoryClass.Create();

            using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true))
            {
                CmPicture pict = new CmPicture(Cache, fileMaker.Filename,
                                               factory.MakeString("Test picture", Cache.DefaultVernWs),
                                               StringUtils.LocalPictures);
                pict.InsertORCAt(tss, 0, para.Hvo,
                                 (int)StTxtPara.StTxtParaTags.kflidContents, 0);
                tss = para.Contents.UnderlyingTsString;
                int cchOrigStringLength = tss.Length;

                NMock.DynamicMock mockIObjectMetaInfoProvider =
                    new DynamicMock(typeof(IObjectMetaInfoProvider));
                mockIObjectMetaInfoProvider.Strict = true;
                mockIObjectMetaInfoProvider.ExpectAndReturn(1, "PictureFolder", StringUtils.LocalPictures);
                para.CreateOwnedObjects(0, 1,
                                        (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance);
                mockIObjectMetaInfoProvider.Verify();

                tss = para.Contents.UnderlyingTsString;
                Assert.AreEqual(cchOrigStringLength, tss.Length);
                string sObjData = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptObjData);
                Guid   guid     = MiscUtils.GetGuidFromObjData(sObjData.Substring(1));

                byte odt = Convert.ToByte(sObjData[0]);
                Assert.AreEqual((byte)FwObjDataTypes.kodtGuidMoveableObjDisp, odt);
                Assert.IsTrue(Cache.GetGuidFromId(pict.Hvo) != guid, "New guid was not inserted");
            }
        }