public void CreateBranchSpecTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d = new Process();

                p4d = Utilities.DeployP4TestServer(TestDir, 8, unicode);

                Server server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        BranchSpec b = new BranchSpec();
                        b.Id          = "newDepotBranch";
                        b.Owner       = "admin";
                        b.Description = "created by perforce";
#pragma warning disable 618
                        b.Options = "locked";
#pragma warning restore 618
                        b.ViewMap = new ViewMap();
                        string v0 = "//depot/main/... //depot/rel1/...";
                        string v1 = "//depot/main/... //depot/rel2/...";
                        string v2 = "//depot/dev/... //depot/main/...";
                        b.ViewMap.Add(v0);
                        b.ViewMap.Add(v1);
                        b.ViewMap.Add(v2);

                        BranchSpec newBranchSpec = rep.CreateBranchSpec(b, null);

                        Assert.IsNotNull(newBranchSpec);
                        Assert.AreEqual("newDepotBranch", newBranchSpec.Id);


                        string v3 = "\"//depot/main/a file with spaces.txt\" \"//depot/rel1/a file with spaces.txt\"";
                        newBranchSpec.ViewMap.Add(v3);
                        newBranchSpec = rep.UpdateBranchSpec(newBranchSpec);
                        Assert.IsNotNull(newBranchSpec);
                        Assert.AreEqual(newBranchSpec.ViewMap.Count, 4);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #2
0
        public void RunAsyncTest(bool unicode)
        {
#if _LOG_TO_FILE
            using (sw = new System.IO.StreamWriter("C:\\Logs\\RunAsyncTestLog.Txt", true))
            {
                LogFile.SetLoggingFunction(LogFn);
#endif
            string serverAddr = "localhost:6666";
            string user       = "******";
            string pass       = string.Empty;
            string ws_client  = "admin_space";

            // turn off exceptions for this test
            ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel;
            P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC;

            Process p4d = null;

            try
            {
                p4d = Utilities.DeployP4TestServer(TestDir, unicode, TestContext.TestName);
                using (serverMT = new P4ServerMT(serverAddr, user, pass, ws_client))
                {
                    P4Server server = serverMT.getServer();
                    if (unicode)
                    {
                        Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode");
                    }
                    else
                    {
                        Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode");
                    }

                    run = true;

                    Thread t1 = new Thread(new ThreadStart(cmdThreadProc1));
                    t1.Name = "RunAsyncTest Thread t1";
                    Thread t2 = new Thread(new ThreadStart(cmdThreadProc2));
                    t2.Name = "RunAsyncTest Thread t2";
                    Thread t3 = new Thread(new ThreadStart(cmdThreadProc3));
                    t3.Name = "RunAsyncTest Thread t3";

                    Thread t4 = new Thread(new ThreadStart(cmdThreadProc4));
                    t4.Name = "RunAsyncTest Thread t4";
                    Thread t5 = new Thread(new ThreadStart(cmdThreadProc5));
                    t5.Name = "RunAsyncTest Thread t5";
                    Thread t6 = new Thread(new ThreadStart(cmdThreadProc6));
                    t6.Name = "RunAsyncTest Thread t6";

                    t1.Start();
                    Thread.Sleep(TimeSpan.FromSeconds(5));                             // wait to start a 4th thread
                    t2.Start();
                    t3.Start();
                    Thread.Sleep(TimeSpan.FromSeconds(5));                             // wait to start a 4th thread

                    run = false;

                    if (t1.Join(1000) == false)
                    {
                        WriteLine("Thread 1 did not cleanly exit");
                        t1.Abort();
                    }
                    if (t2.Join(1000) == false)
                    {
                        WriteLine("Thread 2 did not cleanly exit");
                        t2.Abort();
                    }
                    if (t3.Join(1000) == false)
                    {
                        WriteLine("Thread 3 did not cleanly exit");
                        t3.Abort();
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(15));                             // wait 15 seconds so will disconnect

                    run = true;;

                    t1      = new Thread(new ThreadStart(cmdThreadProc1));
                    t1.Name = "RunAsyncTest Thread t1b";
                    t2      = new Thread(new ThreadStart(cmdThreadProc2));
                    t2.Name = "RunAsyncTest Thread t2b";
                    t3      = new Thread(new ThreadStart(cmdThreadProc3));
                    t3.Name = "RunAsyncTest Thread t3b";

                    t1.Start();
                    t2.Start();
                    t3.Start();
                    Thread.Sleep(TimeSpan.FromSeconds(1));                             // wait to start a 4th thread

                    t4.Start();
                    Thread.Sleep(TimeSpan.FromSeconds(2));                             // wait to start a 5th thread
                    t5.Start();
                    Thread.Sleep(TimeSpan.FromSeconds(3));                             // wait to start a 6th thread
                    t6.Start();

                    Thread.Sleep(TimeSpan.FromSeconds(15));                             // run all threads for 15 seconds

                    run = false;

                    if (t1.Join(1000) == false)
                    {
                        WriteLine("Thread 1 did not cleanly exit");
                        t1.Abort();
                    }
                    if (t2.Join(1000) == false)
                    {
                        WriteLine("Thread 2 did not cleanly exit");
                        t2.Abort();
                    }
                    if (t3.Join(1000) == false)
                    {
                        WriteLine("Thread 3 did not cleanly exit");
                        t3.Abort();
                    }
                    if (t4.Join(1000) == false)
                    {
                        WriteLine("Thread 4 did not cleanly exit");
                        t4.Abort();
                    }
                    if (t5.Join(1000) == false)
                    {
                        WriteLine("Thread 5 did not cleanly exit");
                        t5.Abort();
                    }
                    if (t6.Join(1000) == false)
                    {
                        WriteLine("Thread 6 did not cleanly exit");
                        t6.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail("Test threw an exception: {0}\r\n{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                Utilities.RemoveTestServer(p4d, TestDir);
            }

            // reset the exception level
            P4Exception.MinThrowLevel = oldExceptionLevel;
#if _LOG_TO_FILE
        }
#endif
        }
예제 #3
0
        public void GetUserTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetUser    = "******";
            string targetBadUser = "******";

            Process p4d = null;

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                try
                {
                    if (unicode)
                    {
                        targetUser = "******";
                    }

                    p4d = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                    Server server = new Server(new ServerAddress(uri));

                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        User u = rep.GetUser(targetUser, null);

                        Assert.IsNotNull(u);
                        Assert.AreEqual(targetUser, u.Id);

                        // test reviews for job093785 user
                        // Алексей has 2 review lines, the bug
                        // would skip the 2nd one
                        if (unicode)
                        {
                            Assert.AreEqual(u.Reviews.Count, 2);
                            Assert.AreEqual(u.Reviews[0], "//depot/MyCode/...");
                            Assert.AreEqual(u.Reviews[1], "//depot/TestData/...");
                        }

                        u = rep.GetUser(targetBadUser, null);

                        Assert.IsNull(u);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #4
0
        public void GetUsersTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            Process p4d = null;

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                try
                {
                    p4d = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                    Server server = new Server(new ServerAddress(uri));

                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        IList <User> u = rep.GetUsers(new Options(UsersCmdFlags.IncludeAll, 2));

                        Assert.IsNotNull(u);
                        Assert.AreEqual(2, u.Count);

                        u = rep.GetUsers(new Options(UsersCmdFlags.IncludeAll, -1), "admin", "Alice");

                        Assert.IsNotNull(u);
                        Assert.AreEqual(2, u.Count);

                        u = rep.GetUsers(new Options(UsersCmdFlags.IncludeAll, 3), "A*");

                        Assert.IsNotNull(u);
                        if (unicode)
                        {
                            Assert.AreEqual(2, u.Count);                             // no user 'Alex' on unicode server
                        }
                        else
                        {
                            Assert.AreEqual(3, u.Count);
                        }

                        //DateTime update = new DateTime(2011, 5, 24, 8, 48, 30);
                        //if (unicode)
                        //{
                        //    update = new DateTime(2011, 5, 24, 9, 15, 12);
                        //}
                        //DateTime access = DateTime.Now;
                        //access = access.Subtract(TimeSpan.FromSeconds(access.Second));
                        //Assert.AreEqual(u[0].Updated,update);
                        //Assert.AreEqual(u[0].Accessed.ToLongDateString(), access.ToLongDateString());
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #5
0
        /// <summary>
        ///A test for CheckDepotTypes
        ///</summary>
        public void CheckDepotTypesTest(bool unicode)
        {
            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            Process p4d = null;

            try
            {
                p4d = Utilities.DeployP4TestServer(TestDir, 8, unicode);
                Server     server = new Server(new ServerAddress(uri));
                Repository rep    = new Repository(server);

                using (Connection con = rep.Connection)
                {
                    con.UserName    = user;
                    con.Client      = new Client();
                    con.Client.Name = ws_client;

                    bool connected = con.Connect(null);
                    Assert.IsTrue(connected);

                    Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                    Depot d = new Depot();
                    d.Id          = "LocalDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Local;
                    d.Map         = "LocalDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "RemoteDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Remote;
                    d.Map         = "RemoteDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "StreamDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Stream;
                    d.Map         = "StreamDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "ArchiveDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Archive;
                    d.Map         = "ArchiveDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "UnloadDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Unload;
                    d.Map         = "UnloadDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "TangentDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Tangent;
                    d.Map         = "TangentDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    rep.CreateDepot(d);

                    d             = new Depot();
                    d.Id          = "GraphDepot";
                    d.Description = "created by perforce";
                    d.Owner       = "admin";
                    d.Type        = DepotType.Graph;
                    d.Map         = "GraphDepot/...";
                    d.StreamDepth = "//StreamDepot/1";

                    rep.CreateDepot(d);

                    IList <Depot> dlist = rep.GetDepots();

                    Assert.IsTrue(dlist[0].Type.Equals(DepotType.Archive));
                    Assert.IsTrue(dlist[1].Type.Equals(DepotType.Local));
                    Assert.IsTrue(dlist[2].Type.Equals(DepotType.Stream));
                    Assert.IsTrue(dlist[3].Type.Equals(DepotType.Graph));
                    Assert.IsTrue(dlist[4].Type.Equals(DepotType.Local));
                    Assert.IsTrue(dlist[5].Type.Equals(DepotType.Stream));
                    Assert.IsTrue(dlist[6].Type.Equals(DepotType.Remote));
                    Assert.IsTrue(dlist[7].Type.Equals(DepotType.Stream));
                    Assert.IsTrue(dlist[8].Type.Equals(DepotType.Spec));
                    Assert.IsTrue(dlist[9].Type.Equals(DepotType.Stream));
                    Assert.IsTrue(dlist[10].Type.Equals(DepotType.Tangent));
                    Assert.IsTrue(dlist[11].Type.Equals(DepotType.Stream));
                    Assert.IsTrue(dlist[12].Type.Equals(DepotType.Unload));

                    Options opts = new Options();
                    opts["-t"] = "extension";
                    dlist      = rep.GetDepots(opts);

                    Assert.IsTrue(dlist[0].Type.Equals(DepotType.Extension));
                }
            }
            finally
            {
                Utilities.RemoveTestServer(p4d, TestDir);
            }
        }
예제 #6
0
        public void CreateUserWithInvalidFieldTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetUser        = "******";
            string invalidReviewPath = "test";

            Process p4d = null;

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                try
                {
                    p4d = Utilities.DeployP4TestServer(TestDir, 7, unicode);
                    Server server = new Server(new ServerAddress(uri));

                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        User u = new User();
                        u.Id           = targetUser;
                        u.FullName     = "The New Guy";
                        u.Password     = "******";
                        u.EmailAddress = "*****@*****.**";

                        IList <String> reviewList = new List <String>();
                        reviewList.Add(invalidReviewPath);
                        u.Reviews = reviewList;

                        con.UserName = targetUser;
                        connected    = con.Connect(null);
                        Assert.IsTrue(connected);

                        try
                        {
                            User newGuy = rep.CreateUser(u);
                        }
                        catch (P4Exception e)
                        {
                            Assert.AreEqual(839063594, e.ErrorCode, "Error in user specification.\nPath '%invalidReviewPath' is not under '//...'.\n");
                        }
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #7
0
        public void GetJobsTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        FileSpec path = new FileSpec(new DepotPath(@"//depot/..."), null);

                        IList <Job> u = rep.GetJobs((new Options(JobsCmdFlags.LongDescriptions, null, 2)), path);

                        Assert.IsNotNull(u);
                        Assert.AreEqual(1, u.Count);

                        path = new FileSpec(new DepotPath(@"//depot/..."), null);

                        string jobView = "Test job";
                        u = rep.GetJobs((new Options(JobsCmdFlags.LongDescriptions, jobView, 2)), path);

                        Assert.IsNotNull(u);
                        Assert.AreEqual(1, u.Count);

                        jobView = "status=open";
                        u       = rep.GetJobs((new Options(JobsCmdFlags.LongDescriptions, jobView, 100)), path);

                        Assert.IsNotNull(u);
                        Assert.AreEqual(1, u.Count);

                        u = rep.GetJobs(new Options(JobsCmdFlags.IncludeIntegratedFixes, null, 5), path);

                        Assert.IsNotNull(u);
                        Assert.AreEqual(1, u.Count);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        public void UpdateChangelistOtherUserTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 13, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);
                        int changeID = 120;
                        if (unicode)
                        {
                            changeID = 87;
                        }
                        Changelist c = new Changelist();
                        try
                        {
                            c             = rep.GetChangelist(changeID);
                            c.Description = "new desc\r\nline 2\nline 3";
                            rep.UpdateChangelist(c);
                        }
                        catch (P4Exception ex)
                        {
                            Assert.AreEqual(838932948, ex.ErrorCode, ("can only be updated by user harold"));
                        }

                        Options opts = new Options();
                        opts["-f"] = null;

                        c             = rep.GetChangelist(changeID);
                        c.Description = "new desc\r\nline 2\nline 3";
                        rep.UpdateChangelist(c, opts);

                        Changelist d = rep.GetChangelist(changeID);
                        Assert.AreEqual(d.Description, "new desc\r\nline 2\r\nline 3");
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        ///A test for GetChangelistsjob097882
        ///</summary>
        public void GetChangelistsTestjob097882(bool unicode)
        {
            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            Process p4d = Utilities.DeployP4TestServer(TestDir, 13, unicode);

            Server server = new Server(new ServerAddress(uri));

            try
            {
                Repository rep = new Repository(server);

                using (Connection con = rep.Connection)
                {
                    con.UserName    = user;
                    con.Client      = new Client();
                    con.Client.Name = ws_client;

                    bool connected = con.Connect(null);
                    Assert.IsTrue(connected);

                    Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                    ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.None, null,
                                                                   0, ChangeListStatus.Submitted, null);
                    FileSpec fs = new FileSpec();
                    fs.DepotPath = new DepotPath("//depot/...");

                    //// Creates and initializes a CultureInfo. This is to create
                    //// a date with - as the seperator
                    CultureInfo myCI = new CultureInfo("en-US", false);

                    //// Clones myCI and modifies the DTFI and NFI instances associated with the clone.
                    CultureInfo myCIclone = (CultureInfo)myCI.Clone();
                    myCIclone.DateTimeFormat.DateSeparator = "-";

                    System.Threading.Thread.CurrentThread.CurrentCulture = myCIclone;

                    DateTime dts = new DateTime(2011, 5, 23, 1, 19, 17);
                    DateTime dte = new DateTime(2011, 5, 25, 1, 19, 17);

                    // confirm that the dates have dashes as seperators
                    Assert.IsTrue(dts.ToString().Contains("5-23-2011"));
                    Assert.IsTrue(dte.ToString().Contains("5-25-2011"));

                    DateTimeVersion start = new DateTimeVersion(dts);
                    DateTimeVersion end   = new DateTimeVersion(dte);

                    fs.Version = new VersionRange(start, end);
                    IList <Changelist> changes = rep.GetChangelists(opts, fs);
                    Assert.AreEqual(changes.Count, 4);
                }
            }
            finally
            {
                Utilities.RemoveTestServer(p4d, TestDir);
            }
        }
예제 #10
0
        public void CreateJobTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetJob = "thenewjob";

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 7, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        Job u = new Job();
                        u.Id = targetJob;
                        u.Add("Status", "open");
                        u.Add("User", "admin");
                        u.Add("Description", "this is a test job");

                        Job newGuy = rep.CreateJob(u, null);

                        Job equalJob = rep.GetJob("thenewjob");

                        Assert.IsNotNull(equalJob);
                        Assert.AreEqual(equalJob.Id, newGuy.Id);

                        u    = new Job();
                        u.Id = "new";
                        u.Add("Status", "open");
                        u.Add("User", "admin");
                        u.Add("Description", "this is a test job");

                        newGuy = rep.CreateJob(u, null);

                        equalJob = rep.GetJob(newGuy.Id);

                        Assert.IsNotNull(equalJob);
                        Assert.AreEqual("job000002", newGuy.Id);

                        u    = new Job();
                        u.Id = "new";
                        u.Add("Status", "open");
                        u.Add("User", "admin");
                        u.Add("Description", "this is a test job");

                        newGuy = rep.CreateJob(u, new Options(JobCmdFlags.Input));

                        equalJob = rep.GetJob(newGuy.Id);

                        Assert.IsNotNull(equalJob);
                        Assert.AreEqual("job000003", newGuy.Id);
                        // test to confirm creating a new job without
                        // specifying .Id will not fail if there is a
                        // Job object in the spec
                        u = new Job();
                        u.Add("Job", "targetJobWithoutId");
                        u.Add("Status", "open");
                        u.Add("User", "admin");
                        u.Add("Description", "this is a test job");

                        newGuy = rep.CreateJob(u, null);

                        equalJob = rep.GetJob(u.Id);

                        Assert.IsNotNull(equalJob);
                        Assert.AreEqual("targetJobWithoutId", newGuy.Id);

                        Job testJob = rep.GetJob(u.Id, null);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        ///A test for GetChangelistsjob094473
        ///</summary>
        public void GetChangelistsTestjob094473(bool unicode)
        {
            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            Process p4d    = Utilities.DeployP4TestServer(TestDir, 13, unicode);
            Server  server = new Server(new ServerAddress(uri));

            try
            {
                Repository rep = new Repository(server);

                using (Connection con = rep.Connection)
                {
                    con.UserName    = user;
                    con.Client      = new Client();
                    con.Client.Name = ws_client;

                    bool connected = con.Connect(null);
                    Assert.IsTrue(connected);

                    Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                    ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.None, null,
                                                                   0, ChangeListStatus.Submitted, null);
                    IList <Changelist> changes = rep.GetChangelists(opts, null);

                    // ascii 122 unicode 126
                    Assert.IsNotNull(changes);
                    if (unicode)
                    {
                        Assert.AreEqual(126, changes.Count);
                    }
                    else
                    {
                        Assert.AreEqual(122, changes.Count);
                    }

                    // only get changes @ or above 100
                    opts = new ChangesCmdOptions(ChangesCmdFlags.None, null,
                                                 0, ChangeListStatus.Submitted, null, 100);
                    // ascii 39 (151->100) unicode 51 (150->100)
                    changes = rep.GetChangelists(opts, null);
                    Assert.IsNotNull(changes);
                    if (unicode)
                    {
                        Assert.AreEqual(51, changes.Count);
                        Assert.AreEqual(150, changes[0].Id);
                    }
                    else
                    {
                        Assert.AreEqual(39, changes.Count);
                        Assert.AreEqual(151, changes[0].Id);
                    }

                    // only get changes @ or above 100 and reverse the order
                    opts = new ChangesCmdOptions(ChangesCmdFlags.ReverseOrder, null,
                                                 0, ChangeListStatus.Submitted, null, 100);
                    // ascii 39 (100->151) unicode 51 (100->150)
                    changes = rep.GetChangelists(opts, null);
                    Assert.IsNotNull(changes);
                    if (unicode)
                    {
                        Assert.AreEqual(51, changes.Count);
                        Assert.AreEqual(100, changes[0].Id);
                    }
                    else
                    {
                        Assert.AreEqual(39, changes.Count);
                        Assert.AreEqual(100, changes[0].Id);
                    }
                }
            }
            finally
            {
                Utilities.RemoveTestServer(p4d, TestDir);
            }
        }
        public void GetChangelistWithUTCConversionNoTZDetailsTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        P4Command  cmd = new P4Command(rep, "describe", true, "5");
                        Changelist fromDescribeCommand = new Changelist();

                        P4CommandResult results = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          string.Empty, FormBase.DSTMismatch(server.Metadata));
                        }

                        DateTime unconverted = fromDescribeCommand.ModifiedDate;

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "-200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(-2), fromDescribeCommand.ModifiedDate);

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "+200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(2), fromDescribeCommand.ModifiedDate);

                        fromDescribeCommand = new Changelist();
                        results             = cmd.Run(null);
                        if (results.Success)
                        {
                            fromDescribeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                          "200", FormBase.DSTMismatch(server.Metadata));
                        }

                        Assert.AreEqual(unconverted.AddHours(2), fromDescribeCommand.ModifiedDate);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
        public void GetChangelistWithUTCConversionTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);
                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);
                        Utilities.SetClientRoot(rep, TestDir, unicode, ws_client);

                        P4Command cmd  = new P4Command(rep, "change", true, "5");
                        Options   opts = new Options();
                        opts["-o"] = null;
                        Changelist fromChangeCommand = new Changelist();

                        P4CommandResult results = cmd.Run(opts);
                        if (results.Success)
                        {
                            fromChangeCommand.initialize(rep.Connection);
                            fromChangeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                        server.Metadata.DateTimeOffset, FormBase.DSTMismatch(server.Metadata));
                        }

                        SubmitResults sr = fromChangeCommand.Submit(null);

                        int submitted = 17;
                        if (unicode)
                        {
                            submitted = 13;
                        }

                        cmd               = new P4Command(rep, "change", true, submitted.ToString());
                        opts              = new Options();
                        opts["-o"]        = null;
                        fromChangeCommand = new Changelist();

                        results = cmd.Run(opts);
                        if (results.Success)
                        {
                            fromChangeCommand.initialize(rep.Connection);
                            fromChangeCommand.FromChangeCmdTaggedOutput((results.TaggedOutput[0]),
                                                                        server.Metadata.DateTimeOffset, FormBase.DSTMismatch(server.Metadata));
                        }

                        Changelist fromDescribeCommand = rep.GetChangelist(submitted, null);

                        Assert.AreEqual(fromDescribeCommand.ModifiedDate, fromChangeCommand.ModifiedDate);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #14
0
        public void DeleteGroupTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetGroup = "deleteme";

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 7, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        Group u = new Group();
                        u.Id        = targetGroup;
                        u.UserNames = new List <string> {
                            "Alex"
                        };
                        u.OwnerNames = new List <string> {
                            "Alex"
                        };
                        u.MaxResults = 9999;

                        Group newGuy = rep.CreateGroup(u, null);

                        IList <Group> u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u2);
                        Assert.AreEqual(2, u2.Count);

                        rep.DeleteGroup(u, null);

                        u2 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u2);
                        Assert.AreEqual(1, u2.Count);

                        Group u3 = new Group();
                        u3.Id        = targetGroup;
                        u3.UserNames = new List <string> {
                            "Alex"
                        };
                        u3.OwnerNames = new List <string> {
                            "admin"
                        };
                        u3.MaxResults = 9999;

                        newGuy = rep.CreateGroup(u3, null);
                        try
                        {
                            Assert.Inconclusive("NewGuy {0}", newGuy.Id);
                        }
                        catch { }
                        if (newGuy == null)
                        {
                            P4CommandResult res = con.LastResults;

                            Assert.IsNotNull(res.ErrorList);
                            foreach (P4ClientError e in res.ErrorList)
                            {
                                Assert.Fail("CreateGroup returned null: {0}:{1}", e.ErrorCode, e.ErrorMessage);
                            }
                        }
                        Assert.IsNotNull(newGuy);

                        IList <Group> u4 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u4);
                        if (con.ApiLevel >= 38)
                        {
                            Assert.AreEqual(2, u4.Count);
                        }
                        else
                        {
                            Assert.AreEqual(1, u4.Count);
                        }
                        // delete the group when the user is an owner but not a superuser
                        GroupCmdOptions opts = new GroupCmdOptions(GroupCmdFlags.OwnerAccess);

                        rep.DeleteGroup(u3, opts);

                        u4 = rep.GetGroups(new Options(GroupsCmdFlags.IncludeAllValues, 2));

                        Assert.IsNotNull(u4);
                        Assert.AreEqual(1, u4.Count);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #15
0
        public void IncompleteJobSpecTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetJob = "testJob";

            for (int i = 0; i < 2; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 11, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        try
                        {
                            Job u = new Job();
                            u.Id = targetJob;
                            u.Add("Status", "open");
                            u.Add("User", "admin");
                            Job job = rep.CreateJob(u, null);
                        }
                        catch (P4Exception e)
                        {
                            Assert.AreEqual(822153261, e.ErrorCode, "Error in job specification.\nMissing required field 'Description'.\n");
                        }

                        try
                        {
                            Job u = new Job();
                            u.Id = targetJob;
                            u.Add("Status", "open");
                            u.Add("Description", "this is a test job");
                            Job job = rep.CreateJob(u, null);
                        }
                        catch (P4Exception e)
                        {
                            Assert.AreEqual(822153261, e.ErrorCode, "Error in job specification.\nMissing required field 'User'.\n");
                        }

                        try
                        {
                            Job u = new Job();
                            u.Id = targetJob;
                            u.Add("Status", "open");
                            u.Add("User", "admin");
                            Job job = rep.CreateJob(u, null);
                        }
                        catch (P4Exception e)
                        {
                            Assert.AreEqual(822153261, e.ErrorCode, "Error in job specification.\nMissing required field 'Status'.\n");
                        }
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #16
0
        public void CreateGroupTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";

            string targetGroup = "thenewguys";

            for (int i = 0; i < 2; i++)             // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 7, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        bool connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        Group u = new Group();
                        u.Id        = targetGroup;
                        u.UserNames = new List <string> {
                            "Alex"
                        };
                        u.OwnerNames = new List <string> {
                            "Alex"
                        };
                        u.MaxResults = 9999;

                        //GroupOptions uFlags = new GroupOptions(GroupFlags.Force);
                        Group newGuy = rep.CreateGroup(u, null);

                        Assert.IsNotNull(newGuy);
                        Assert.AreEqual(targetGroup, newGuy.Id);

                        // create a group connected as admin user with owner Alex and
                        // users Alice and Alex (no -A needed)
                        Group  group        = new Group();
                        string targetGroup2 = "Mygroup";
                        group.Id        = targetGroup2;
                        group.UserNames = new List <string> {
                            "Alice", "Alex"
                        };
                        group.OwnerNames = new List <string> {
                            "Alex"
                        };

                        Group newGuy2 = rep.CreateGroup(group, null);
                        Assert.IsNotNull(newGuy2);
                        Assert.AreEqual(targetGroup2, newGuy2.Id);

                        bool disconnected = con.Disconnect(null);
                        Assert.IsTrue(disconnected);

                        // connect as admin level user Alex
                        con.UserName    = "******";
                        con.Client      = new Client();
                        con.Client.Name = "Alex_space";

                        connected = con.Connect(null);
                        Assert.IsTrue(connected);

                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);

                        // create a group as Alex with owner Alex using -A
                        Group  Alex_group   = new Group();
                        string targetGroup3 = "Alex_group";
                        Alex_group.Id        = targetGroup3;
                        Alex_group.UserNames = new List <string> {
                            "Alice", "Alex"
                        };
                        Alex_group.OwnerNames = new List <string> {
                            "Alex"
                        };

                        Group newGuy3 = rep.CreateGroup(Alex_group, new Options(GroupCmdFlags.AdminAdd));
                        Assert.IsNotNull(newGuy3);
                        Assert.AreEqual(targetGroup3, newGuy3.Id);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }
예제 #17
0
        public void SubmitOptionsShelvedTest()
        {
            bool unicode = false;

            string uri       = "localhost:6666";
            string user      = "******";
            string pass      = string.Empty;
            string ws_client = "admin_space";


            for (int i = 0; i < 1; i++) // run once for ascii, once for unicode
            {
                Process p4d    = Utilities.DeployP4TestServer(TestDir, 6, unicode);
                Server  server = new Server(new ServerAddress(uri));
                try
                {
                    Repository rep = new Repository(server);

                    using (Connection con = rep.Connection)
                    {
                        con.UserName    = user;
                        con.Client      = new Client();
                        con.Client.Name = ws_client;

                        Assert.AreEqual(con.Status, ConnectionStatus.Disconnected);
                        Assert.AreEqual(con.Server.State, ServerState.Unknown);
                        Assert.IsTrue(con.Connect(null));
                        Assert.AreEqual(con.Server.State, ServerState.Online);
                        Assert.AreEqual(con.Status, ConnectionStatus.Connected);
                        Assert.AreEqual("admin", con.Client.OwnerName);
                        Utilities.SetClientRoot(rep, TestDir, unicode, ws_client);

                        Changelist change = new Changelist(5, true);
                        change.initialize(con);

                        FileSpec fs = FileSpec.DepotSpec("//depot/MyCode/NewFile.txt");
                        ShelveFilesCmdOptions shelvedOptions = new ShelveFilesCmdOptions(ShelveFilesCmdFlags.None, null, 5);
                        rep.Connection.Client.ShelveFiles(shelvedOptions, fs);
                        rep.Connection.Client.RevertFiles(null, fs);

                        SubmitResults sr = null;

                        try
                        {
                            SubmitCmdOptions submitOptions = new SubmitCmdOptions(Perforce.P4.SubmitFilesCmdFlags.SubmitShelved, 5, null, null, null);
                            sr = change.Submit(submitOptions);
                        }
                        catch (P4Exception e)
                        {
                            String msg = String.Format("Command '{0}' throws exception '{1}' \r\n StackTrace: {2}",
                                                       e.CmdLine,
                                                       e.Message,
                                                       e.StackTrace);
                            Assert.IsTrue(false, msg);
                        }

                        Assert.IsNotNull(sr);
                        Assert.AreEqual(1, sr.Files.Count);
                    }
                }
                finally
                {
                    Utilities.RemoveTestServer(p4d, TestDir);
                }
                unicode = !unicode;
            }
        }