Exemplo n.º 1
0
        public void FieldExists()
        {
            var failed_fields = new List <string> ();

            Errors = 0;
            int n = 0;

            foreach (var p in AllProperties())
            {
                var f = p.GetCustomAttribute <FieldAttribute> ();
                if (f == null)
                {
                    continue;
                }

                string name = f.SymbolName;
                if (Skip(name, f.LibraryName))
                {
                    continue;
                }

                string path = FindLibrary(f.LibraryName);
                IntPtr lib  = Dlfcn.dlopen(path, 0);
                if (lib == IntPtr.Zero)
                {
                    ReportError("Could not open the library '{0}' to find the field '{1}': {2}", path, name, Dlfcn.dlerror());
                    failed_fields.Add(name);
                }
                else if (Dlfcn.GetIndirect(lib, name) == IntPtr.Zero)
                {
                    ReportError("Could not find the field '{0}' in {1}", name, path);
                    failed_fields.Add(name);
                }
                Dlfcn.dlclose(lib);
                n++;
            }
            Assert.AreEqual(0, Errors, "{0} errors found in {1} fields validated: {2}", Errors, n, string.Join(", ", failed_fields));
        }