Exemplo n.º 1
0
        public void DefaultParatextProject()
        {
            CheckDisposed();

            IParatextProjectProxy proj = new ParatextProjectProxyClass();

            Assert.AreEqual(string.Empty, proj.VernTransProj, "VernTransProj not empty.");
            Assert.AreEqual(string.Empty, proj.NotesTransProj, "NotesTransProj not empty.");
            Assert.AreEqual(string.Empty, proj.BackTransProj, "BackTransProj not empty.");
            Assert.AreEqual(0, proj.NumberOfMappings, "Number of Mappings not zero");
        }
Exemplo n.º 2
0
        public void RescanParatextProjectFiles()
        {
            CheckDisposed();

            // Set up a couple of Paratext projects and save the information in a blob.
            IParatextProjectProxy projectProxy = new ParatextProjectProxyClass();

            projectProxy.VernTransProj = "KAM";
            projectProxy.BackTransProj = "TEV";

            Assert.AreEqual(44, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Vern),
                            "Wrong Number of Vernacular Markers");
            Assert.AreEqual(158, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Back),
                            "Wrong Number of Back Translation Markers");

            byte[] blob = (byte[])projectProxy.AsSafeArray;

            // Recreate the proxy and initialize it with the blob we just created.
            projectProxy = new ParatextProjectProxyClass();
            projectProxy.InitializeFromSafeArray(blob);

            // Verify there are still the same number of mappings after loading blob.
            Assert.AreEqual(44, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Vern),
                            "Wrong Number of Vernacular Markers");
            Assert.AreEqual(158, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Back),
                            "Wrong Number of Back Translation Markers");

            try
            {
                // Unzip a couple of .sty files containing more markers than when the projects
                // were scanned before the blob above was saved.
                Unpacker.UnpackParatextStyWithExtraMarkers();

                // Recan the Vernacular domain to catch the extra 2 markers.
                projectProxy.RefreshDomainMarkers(MarkerDomain.MD_Vern);

                Assert.AreEqual(46, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Vern),
                                "Wrong Number of Vernacular Markers after rescan");

                // Recan the Back Trans. domain to catch the extra 2 markers.
                projectProxy.RefreshDomainMarkers(MarkerDomain.MD_Back);

                Assert.AreEqual(161, projectProxy.get_NumberOfMappingsForDomain(MarkerDomain.MD_Back),
                                "Wrong Number of Back Translation Markers after recan");
            }
            finally
            {
                // This will restore the original .sty files for other tests.
                Unpacker.UnPackParatextTestProjects();
            }
        }
Exemplo n.º 3
0
        public void Test_AreProjectsAccessible_TheSequel()
        {
            CheckDisposed();

            // Set up a couple of Paratext projects and save the information in a blob.
            IParatextProjectProxy projectProxy = new ParatextProjectProxyClass();

            projectProxy.VernTransProj = "KAM";
            projectProxy.BackTransProj = "TEV";
            byte[] blob = (byte[])projectProxy.AsSafeArray;

            // Recreate the proxy and initialize it with the blob we just created.
            projectProxy = new ParatextProjectProxyClass();
            projectProxy.InitializeFromSafeArray(blob);

            // Verify the AreProjectsAccessible property works properly. All projects should
            // be accessible.
            int inaccessibleProjects = projectProxy.AreProjectsAccessible;

            Assert.AreEqual(0, inaccessibleProjects, "Projects were not accessible");

            // Verify the get_IsValidProject method works properly.
            Assert.AreEqual(1, projectProxy.get_IsValidProject(MarkerDomain.MD_Vern),
                            "Vernacular invalid");
            Assert.AreEqual(1, projectProxy.get_IsValidProject(MarkerDomain.MD_Back),
                            "Back Trans. invalid");

            try
            {
                // Now blow away the KAM.ssf (i.e. vernacular project file) settings file and
                // check if it is still accessible. It should not be.
                File.Delete(Unpacker.PtProjectTestFolder + "KAM.ssf");

                // Verify the AreProjectsAccessible property works properly. Only the
                // vernacular project should be inaccessible.
                inaccessibleProjects = projectProxy.AreProjectsAccessible;
                Assert.IsTrue((inaccessibleProjects & (int)MarkerDomain.MD_Vern) != 0,
                              "Vernacular is accessible");
                Assert.AreEqual((inaccessibleProjects & (int)MarkerDomain.MD_Back), 0,
                                "Back Trans is inaccessible");
                Assert.AreEqual((inaccessibleProjects & (int)MarkerDomain.MD_Note), 0,
                                "Notes is inaccessible");

                // Verify the get_IsValidProject method works properly.
                Assert.AreEqual(0, projectProxy.get_IsValidProject(MarkerDomain.MD_Vern),
                                "Vernacular valid");
                Assert.AreEqual(1, projectProxy.get_IsValidProject(MarkerDomain.MD_Back),
                                "Back Trans. invalid");

                // Check that the inaccessible file is correctly named.
                string sInvalidFile;
                projectProxy.GetProjectFilename(MarkerDomain.MD_Vern, out sInvalidFile);
                Assert.IsTrue(sInvalidFile.EndsWith("KAM.ssf"));

                // Now check that AreProjectsAccessible works properly when a proxy is
                // initialized from a blob after the settings file was deleted.
                projectProxy = new ParatextProjectProxyClass();
                projectProxy.InitializeFromSafeArray(blob);

                inaccessibleProjects = projectProxy.AreProjectsAccessible;
                Assert.IsTrue((inaccessibleProjects & (int)MarkerDomain.MD_Vern) != 0,
                              "Vernacular is accessible");
                Assert.IsTrue((inaccessibleProjects & (int)MarkerDomain.MD_Back) == 0,
                              "Back Trans is inaccessible");
                Assert.IsTrue((inaccessibleProjects & (int)MarkerDomain.MD_Note) == 0,
                              "Notes is inaccessible");

                // Check that the inaccessible file is correctly named.
                projectProxy.GetProjectFilename(MarkerDomain.MD_Vern, out sInvalidFile);
                Assert.IsTrue(sInvalidFile.EndsWith("KAM.ssf"));
            }
            finally
            {
                // Unzip the paratext projects again since we just deleted the KAM.ssf.
                Unpacker.UnPackParatextTestProjects();
            }
        }
Exemplo n.º 4
0
        public void Test_AreProjectsAccessible()
        {
            CheckDisposed();

            ///	This test shows how to use the three new methods on the ParatextProjectProxy object.
            ///	To effectivly run a test in this environment, a resource file is needed that has PT
            ///	projects that can be added to the ParatextProjectProxy object.  With valid projects
            ///	the put assignments will not raise an exception.
            ///

            IParatextProjectProxy ptProject = new ParatextProjectProxyClass();

            MarkerDomain md = MarkerDomain.MD_Unknown;

            if (md == MarkerDomain.MD_Back)                     // needed to remove the CS0219 warning...
            {
                md = MarkerDomain.MD_Note;
            }

            string projectName = "";

            try
            {
                md                      = MarkerDomain.MD_Vern;
                projectName             = "PTVern";
                ptProject.VernTransProj = projectName;

                md                      = MarkerDomain.MD_Back;
                projectName             = "PTBack";
                ptProject.VernTransProj = projectName;

                md                      = MarkerDomain.MD_Note;
                projectName             = "PTNote";
                ptProject.VernTransProj = projectName;
            }
            catch
            {
                string msg;
                msg = "Unable to Add project: " + projectName;
                System.Diagnostics.Debug.WriteLine(msg);
            }

            int markerDomainsNotAccessible = ptProject.AreProjectsAccessible;

            if (markerDomainsNotAccessible != 0)
            {
                string projectFileName, msg;

                if (((byte)(markerDomainsNotAccessible) & (byte)(MarkerDomain.MD_Vern)) != 0)
                {
                    ptProject.GetProjectFilename(MarkerDomain.MD_Vern, out projectFileName);
                    msg = "Project file not Accessible: " + projectFileName;
                    System.Diagnostics.Debug.WriteLine(msg);
                }

                if (((byte)(markerDomainsNotAccessible) & (byte)(MarkerDomain.MD_Back)) != 0)
                {
                    ptProject.GetProjectFilename(MarkerDomain.MD_Back, out projectFileName);
                    msg = "Project file not Accessible: " + projectFileName;
                    System.Diagnostics.Debug.WriteLine(msg);
                }

                if (((byte)(markerDomainsNotAccessible) & (byte)(MarkerDomain.MD_Note)) != 0)
                {
                    ptProject.GetProjectFilename(MarkerDomain.MD_Note, out projectFileName);
                    msg = "Project file not Accessible: " + projectFileName;
                    System.Diagnostics.Debug.WriteLine(msg);
                }
            }
        }