~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ngit/NGit.Test/NGit/IndexModificationTimesTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This code is derived from jgit (http://eclipse.org/jgit).
 
3
Copyright owners are documented in jgit's IP log.
 
4
 
 
5
This program and the accompanying materials are made available
 
6
under the terms of the Eclipse Distribution License v1.0 which
 
7
accompanies this distribution, is reproduced below, and is
 
8
available at http://www.eclipse.org/org/documents/edl-v10.php
 
9
 
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or
 
13
without modification, are permitted provided that the following
 
14
conditions are met:
 
15
 
 
16
- Redistributions of source code must retain the above copyright
 
17
  notice, this list of conditions and the following disclaimer.
 
18
 
 
19
- Redistributions in binary form must reproduce the above
 
20
  copyright notice, this list of conditions and the following
 
21
  disclaimer in the documentation and/or other materials provided
 
22
  with the distribution.
 
23
 
 
24
- Neither the name of the Eclipse Foundation, Inc. nor the
 
25
  names of its contributors may be used to endorse or promote
 
26
  products derived from this software without specific prior
 
27
  written permission.
 
28
 
 
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
42
*/
 
43
 
 
44
using NGit;
 
45
using NGit.Api;
 
46
using NGit.Dircache;
 
47
using Sharpen;
 
48
 
 
49
namespace NGit
 
50
{
 
51
        [NUnit.Framework.TestFixture]
 
52
        public class IndexModificationTimesTest : RepositoryTestCase
 
53
        {
 
54
                /// <exception cref="System.Exception"></exception>
 
55
                [NUnit.Framework.Test]
 
56
                public virtual void TestLastModifiedTimes()
 
57
                {
 
58
                        Git git = new Git(db);
 
59
                        string path = "file";
 
60
                        WriteTrashFile(path, "content");
 
61
                        string path2 = "file2";
 
62
                        WriteTrashFile(path2, "content2");
 
63
                        git.Add().AddFilepattern(path).Call();
 
64
                        git.Add().AddFilepattern(path2).Call();
 
65
                        git.Commit().SetMessage("commit").Call();
 
66
                        DirCache dc = db.ReadDirCache();
 
67
                        DirCacheEntry entry = dc.GetEntry(path);
 
68
                        DirCacheEntry entry2 = dc.GetEntry(path);
 
69
                        NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
 
70
                                );
 
71
                        NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
 
72
                                );
 
73
                        WriteTrashFile(path, "new content");
 
74
                        git.Add().AddFilepattern(path).Call();
 
75
                        git.Commit().SetMessage("commit2").Call();
 
76
                        dc = db.ReadDirCache();
 
77
                        entry = dc.GetEntry(path);
 
78
                        entry2 = dc.GetEntry(path);
 
79
                        NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
 
80
                                );
 
81
                        NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
 
82
                                );
 
83
                }
 
84
 
 
85
                /// <exception cref="System.Exception"></exception>
 
86
                [NUnit.Framework.Test]
 
87
                public virtual void TestModify()
 
88
                {
 
89
                        Git git = new Git(db);
 
90
                        string path = "file";
 
91
                        WriteTrashFile(path, "content");
 
92
                        git.Add().AddFilepattern(path).Call();
 
93
                        git.Commit().SetMessage("commit").Call();
 
94
                        DirCache dc = db.ReadDirCache();
 
95
                        DirCacheEntry entry = dc.GetEntry(path);
 
96
                        long masterLastMod = entry.LastModified;
 
97
                        git.Checkout().SetCreateBranch(true).SetName("side").Call();
 
98
                        Sharpen.Thread.Sleep(10);
 
99
                        string path2 = "file2";
 
100
                        WriteTrashFile(path2, "side content");
 
101
                        git.Add().AddFilepattern(path2).Call();
 
102
                        git.Commit().SetMessage("commit").Call();
 
103
                        dc = db.ReadDirCache();
 
104
                        entry = dc.GetEntry(path);
 
105
                        long sideLastMode = entry.LastModified;
 
106
                        Sharpen.Thread.Sleep(2000);
 
107
                        WriteTrashFile(path, "uncommitted content");
 
108
                        git.Checkout().SetName("master").Call();
 
109
                        dc = db.ReadDirCache();
 
110
                        entry = dc.GetEntry(path);
 
111
                        NUnit.Framework.Assert.IsTrue(masterLastMod == sideLastMode, "shall have equal mod time!"
 
112
                                );
 
113
                        NUnit.Framework.Assert.IsTrue(entry.LastModified == masterLastMod, "shall not equal master timestamp!"
 
114
                                );
 
115
                }
 
116
        }
 
117
}