Пример #1
0
        public bool TestGetGroupCount()
        {
            NcGroup group;
            NcFile  file = null;

            try {
                file  = newFile(filePath);
                group = file;
                int groupCount;
                groupCount = group.GetGroupCount(GroupLocation.AllGrps);
                Assert.Equals(groupCount, 1); // Only the root group/file so no groups are defined
                NcGroup childGroup = group.AddGroup("child1");
                Assert.False(childGroup.IsNull());
                Assert.Equals(group.GetGroupCount(GroupLocation.AllGrps), 2);
                Dictionary <string, NcGroup> groups = group.GetGroups(GroupLocation.AllGrps);
                for (int i = 0; i < groups.Count; i++)
                {
                    KeyValuePair <string, NcGroup> k = groups.ElementAt(i);
                    if (i == 0)
                    {
                        Assert.Equals(k.Key, "/");
                    }
                    else if (i == 1)
                    {
                        Assert.Equals(k.Key, "child1");
                    }
                }
            } finally {
                file.Close();
            }

            CheckDelete(filePath);
            return(true);
        }
Пример #2
0
        public bool TestGetParentGroup()
        {
            NcGroup group;
            NcGroup grpTest;
            NcFile  file = null;

            group = new NcGroup();
            try {
                grpTest = group.GetParentGroup();
                Assert.True(grpTest.IsNull());
                throw new AssertFailedException("NcNullGrp not thrown");
            } catch (exceptions.NcNullGrp) {
            }

            try {
                file  = newFile(filePath);
                group = file.GetParentGroup();
                Assert.True(group.IsNull());
            } finally {
                file.Close();
            }
            return(true);
        }
Пример #3
0
        public bool TestNestedGroups()
        {
            NcFile file = null;
            NcDim  dim;
            Dictionary <string, NcGroup> groups;

            try {
                file = TestHelper.NewFile(filePath);
                NcGroup a = file.AddGroup("a");
                Assert.False(a.IsNull());
                NcGroup b = file.AddGroup("b");
                Assert.False(b.IsNull());
                NcGroup a1 = a.AddGroup("a1");
                Assert.False(a1.IsNull());
                NcGroup a2 = a.AddGroup("a2");
                Assert.False(a2.IsNull());
                NcGroup b1 = b.AddGroup("b1");
                Assert.False(b1.IsNull());
                NcGroup b2 = b.AddGroup("b2");
                Assert.False(b2.IsNull());

                Assert.Equals(file.GetGroupCount(GroupLocation.AllGrps), 7);
                Assert.Equals(file.GetGroupCount(GroupLocation.AllChildrenGrps), 6);
                Assert.Equals(b2.GetGroupCount(GroupLocation.ParentsGrps), 2);
                Assert.Equals(a2.GetGroupCount(GroupLocation.ParentsGrps), 2);
                Assert.True(file.GetGroups(GroupLocation.AllChildrenGrps).ContainsKey("b1"));
                groups = a1.GetGroups(GroupLocation.ParentsGrps);
                Assert.True(groups.ContainsKey("/") && groups["/"].GetId() == file.GetId());
                Assert.Equals(file.GetGroups("b1", GroupLocation.AllChildrenGrps).Count, 1);
                Assert.True(file.GetGroup("a2", GroupLocation.ChildrenGrps).IsNull());
                Assert.Equals(file.GetGroup("a2", GroupLocation.AllChildrenGrps).GetId(), a2.GetId());
                Assert.True(file.IsRootGroup());
                Assert.False(a.IsRootGroup());

                foreach (KeyValuePair <string, NcGroup> group in file.GetGroups(GroupLocation.AllGrps))
                {
                    dim = group.Value.AddDim("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), 20);
                    NcVar v   = group.Value.AddVar("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), NcUint64.Instance, dim);
                    NcAtt att = group.Value.PutAtt("Attr" + (group.Value.IsRootGroup() ? "Root" : group.Key), "Value");
                    Assert.False(v.IsNull());
                    Assert.Equals(file.GetVar(v.GetName(), Location.All).GetId(), v.GetId());
                }


                Assert.Equals(file.GetVarCount(Location.All), 7);
                Assert.Equals(file.GetVars(Location.All).Count, 7);
                foreach (KeyValuePair <string, NcVar> gvar in file.GetVars(Location.All))
                {
                    Assert.Equals(gvar.Key, gvar.Value.GetName());
                    NcGroup g = gvar.Value.GetParentGroup();
                    Assert.Equals(gvar.Key, "time" + (g.IsRootGroup() ? "Root" : g.GetName()));
                }
                Assert.Equals(file.GetVars("timeRoot", Location.All).Count, 1);

                Assert.Equals(file.GetAttCount(Location.All), 7);
                Assert.Equals(file.GetAtts(Location.All).Count, 7);
                foreach (KeyValuePair <string, NcGroupAtt> k in file.GetAtts(Location.All))
                {
                    Assert.Equals(k.Value.GetValues(), "Value");
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }