Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

44
eglib/test/Makefile.am Normal file
View File

@@ -0,0 +1,44 @@
EXTRA_DIST = UTF-8.txt UTF-16BE.txt UTF-16LE.txt UTF-32BE.txt UTF-32LE.txt
SOURCES = \
test.c \
test.h \
tests.h \
driver.c \
hashtable.c \
string-util.c \
string.c \
slist.c \
sizes.c \
ptrarray.c \
list.c \
array.c \
fake.c \
path.c \
queue.c \
shell.c \
spawn.c \
timer.c \
file.c \
pattern.c \
dir.c \
markup.c \
unicode.c \
utf8.c \
endian.c \
module.c \
memory.c
test_eglib_SOURCES = $(SOURCES)
test_eglib_CFLAGS = -Wall -DEGLIB_TESTS=1 -D_FORTIFY_SOURCE=2 -I$(srcdir)/../src -I../src -DDRIVER_NAME=\"EGlib\"
test_eglib_LDADD = ../src/libeglib.la $(LIBICONV)
run-eglib: all
srcdir=`readlink -f $(srcdir)` ./test-eglib
noinst_PROGRAMS = test-eglib
run-both: run-eglib
MAINTAINERCLEANFILES = Makefile.in

1029
eglib/test/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

113
eglib/test/README Normal file
View File

@@ -0,0 +1,113 @@
EGlib Unit Testing
===============================================================================
1. Writing new tests
2. Using the test driver
===============================================================================
1. Writing new tests
===============================================================================
Tests are easy to write, but must be grouped in to logical cases. For instance,
the GPtrArray group has a number of tests that cover the entire GPtrArray
implementation.
These logical case groups should be in a single C file, and must have
three elements:
#include <glib.h>
#include "test.h"
...
<define test implementations>
...
static Test groupname_tests [] = {
{"groupname_test1", groupname_test1},
{"groupname_test1", groupname_test2},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(groupname_tests_init, groupname_tests)
A test implementation should look like:
RESULT groupname_test1()
{
<perform the test>
if(test_failed) {
return FAILED("reason: %s", "this works like printf");
}
return OK; /* just NULL, but OK is cute */
}
Once a test group is written, it needs to be added to the groups table
in tests.h:
DEFINE_TEST_GROUP_INIT_H(groupname_tests_init) // same as in impl
static Group test_groups [] = {
...
{"groupname", groupname_tests_init}
...
};
===============================================================================
2. Using the test driver
===============================================================================
When tests are written, they are rebuilt with make. Two programs will be
built:
test-eglib: the test driver and tests linked against eglib
test-glib: the test driver and tests linked against system glib-2.0
Each driver program works exactly the same. Running test-eglib will run
the tests against eglib, and test-glib against glib-2.0.
The test driver supports a few options to allow for performance measuring:
--help show all options and available test groups
--time time the overall run and report it, even if --quiet is set
--quiet do not print test results, useful for timing
--iterations N run all or specified test groups N times
Run "test-eglib --help" for more details.
Example: run the ptrarray test group 100000 times and only print the time
it took to perform all iterations
./test-eglib -tqi 100000 ptrarray
Example: show single iteration of test output for two groups
./test-eglib ptrarray hashtable
Example: show test output of all available groups
./test-eglib
The 'test-both' script can be used to run both test-eglib and test-glib
with the same options back to back:
$ ./test-both -tqi 100000 ptrarray
EGlib Total Time: 1.1961s
GLib Total Time: 0.955957s
test-both also has a nice --speed-compare mode that shows comparison
information about EGlib vs GLib. It can run all tests or specific tests
with a configurable number of iterations. --speed-compare mode always runs
the drivers with -qtni
The syntax for --speed-compare is:
./test-both --speed-compare [ITERATIONS] [GROUPS...]
$ ./test-both --speed-compare Runs all tests with default iterations
$ ./test-both --speed-compare 500 Runs all tests with 500 iterations
$ ./test-both --speed-compare ptrarray Runs ptrarray test with default
iterations

BIN
eglib/test/UTF-16BE.txt Normal file

Binary file not shown.

BIN
eglib/test/UTF-16LE.txt Normal file

Binary file not shown.

BIN
eglib/test/UTF-32BE.txt Normal file

Binary file not shown.

BIN
eglib/test/UTF-32LE.txt Normal file

Binary file not shown.

212
eglib/test/UTF-8.txt Normal file
View File

@@ -0,0 +1,212 @@
UTF-8 encoded sample plain-text file
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Markus Kuhn [ˈmaʳkʊs kuːn] <http://www.cl.cam.ac.uk/~mgk25/> — 2002-07-25
The ASCII compatible UTF-8 encoding used in this plain-text file
is defined in Unicode, ISO 10646-1, and RFC 2279.
Using Unicode/UTF-8, you can write in emails and source code things such as
Mathematics and sciences:
∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ⎧⎡⎛┌─────┐⎞⎤⎫
⎪⎢⎜│a²+b³ ⎟⎥⎪
∀x∈: ⌈x⌉ = x⌋, α ∧ ¬β = ¬(¬α β), ⎪⎢⎜│───── ⎟⎥⎪
⎪⎢⎜⎷ c₈ ⎟⎥⎪
⊆ ℕ₀ ⊂ , ⎨⎢⎜ ⎟⎥⎬
⎪⎢⎜ ∞ ⎟⎥⎪
⊥ < a ≠ b ≡ c ≤ d ≪ ⇒ (⟦A⟧ ⇔ ⟪B⟫), ⎪⎢⎜ ⎲ ⎟⎥⎪
⎪⎢⎜ ⎳aⁱ-bⁱ⎟⎥⎪
2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm ⎩⎣⎝i=1 ⎠⎦⎭
Linguistics and dictionaries:
ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn
Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]
APL:
((VV)=V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
Nicer typography in plain text files:
╔══════════════════════════════════════════╗
║ ║
║ • single and “double” quotes ║
║ ║
║ • Curly apostrophes: “Weve been here” ║
║ ║
║ • Latin-1 apostrophe and accents: '´` ║
║ ║
║ • deutsche „Anführungszeichen“ ║
║ ║
║ • †, ‡, ‰, •, 34, —, 5/+5, ™, … ║
║ ║
║ • ASCII safety test: 1lI|, 0OD, 8B ║
║ ╭─────────╮ ║
║ • the euro symbol: │ 14.95 € │ ║
║ ╰─────────╯ ║
╚══════════════════════════════════════════╝
Combining characters:
STARGΛ̊TE SG-1, a = v̇ = r̈, a⃑ ⊥ b⃑
Greek (in Polytonic):
The Greek anthem:
Σὲ γνωρίζω ἀπὸ τὴν κόψη
τοῦ σπαθιοῦ τὴν τρομερή,
σὲ γνωρίζω ἀπὸ τὴν ὄψη
ποὺ μὲ βία μετράει τὴ γῆ.
᾿Απ᾿ τὰ κόκκαλα βγαλμένη
τῶν ῾Ελλήνων τὰ ἱερά
καὶ σὰν πρῶτα ἀνδρειωμένη
χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά!
From a speech of Demosthenes in the 4th century BC:
Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα, ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν
οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι,
οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν
ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον
τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι
γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν
προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους
σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ
τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ
τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς
τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον.
Δημοσθένους, Γ´ ᾿Ολυνθιακὸς
Georgian:
From a Unicode conference invitation:
გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო
კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს,
ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს
ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი,
ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება
ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში,
ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში.
Russian:
From a Unicode conference invitation:
Зарегистрируйтесь сейчас на Десятую Международную Конференцию по
Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.
Конференция соберет широкий круг экспертов по вопросам глобального
Интернета и Unicode, локализации и интернационализации, воплощению и
применению Unicode в различных операционных системах и программных
приложениях, шрифтах, верстке и многоязычных компьютерных системах.
Thai (UCS Level 2):
Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese
classic 'San Gua'):
[----------------------------|------------------------]
๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช พระปกเกศกองบู๊กู้ขึ้นใหม่
สิบสองกษัตริย์ก่อนหน้าแลถัดไป สององค์ไซร้โง่เขลาเบาปัญญา
ทรงนับถือขันทีเป็นที่พึ่ง บ้านเมืองจึงวิปริตเป็นนักหนา
โฮจิ๋นเรียกทัพทั่วหัวเมืองมา หมายจะฆ่ามดชั่วตัวสำคัญ
เหมือนขับไสไล่เสือจากเคหา รับหมาป่าเข้ามาเลยอาสัญ
ฝ่ายอ้องอุ้นยุแยกให้แตกกัน ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
พลันลิฉุยกุยกีกลับก่อเหตุ ช่างอาเพศจริงหนาฟ้าร้องไห้
ต้องรบราฆ่าฟันจนบรรลัย ฤๅหาใครค้ำชูกู้บรรลังก์ ฯ
(The above is a two-column text. If combining characters are handled
correctly, the lines of the second column should be aligned with the
| character above.)
Ethiopian:
Proverbs in the Amharic language:
ሰማይ አይታረስ ንጉሥ አይከሰስ።
ብላ ካለኝ እንደአባቴ በቆመጠኝ።
ጌጥ ያለቤቱ ቁምጥና ነው።
ደሀ በሕልሙ ቅቤ ባይጠጣ ንጣት በገደለው።
የአፍ ወለምታ በቅቤ አይታሽም።
አይጥ በበላ ዳዋ ተመታ።
ሲተረጉሙ ይደረግሙ።
ቀስ በቀስ፥ ዕንቁላል በእግሩ ይሄዳል።
ድር ቢያብር አንበሳ ያስር።
ሰው እንደቤቱ እንጅ እንደ ጉረቤቱ አይተዳደርም።
እግዜር የከፈተውን ጉሮሮ ሳይዘጋው አይድርም።
የጎረቤት ሌባ፥ ቢያዩት ይስቅ ባያዩት ያጠልቅ።
ሥራ ከመፍታት ልጄን ላፋታት።
ዓባይ ማደሪያ የለው፥ ግንድ ይዞ ይዞራል።
የእስላም አገሩ መካ የአሞራ አገሩ ዋርካ።
ተንጋሎ ቢተፉ ተመልሶ ባፉ።
ወዳጅህ ማር ቢሆን ጨርስህ አትላሰው።
እግርህን በፍራሽህ ልክ ዘርጋ።
Runes:
ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ
(Old English, which transcribed into Latin reads 'He cwaeth that he
bude thaem lande northweardum with tha Westsae.' and means 'He said
that he lived in the northern land near the Western Sea.')
Braille:
⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌
⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠙⠑⠁⠙⠒ ⠞⠕ ⠃⠑⠛⠔ ⠺⠊⠹⠲ ⡹⠻⠑ ⠊⠎ ⠝⠕ ⠙⠳⠃⠞
⠱⠁⠞⠑⠧⠻ ⠁⠃⠳⠞ ⠹⠁⠞⠲ ⡹⠑ ⠗⠑⠛⠊⠌⠻ ⠕⠋ ⠙⠊⠎ ⠃⠥⠗⠊⠁⠇ ⠺⠁⠎
⠎⠊⠛⠝⠫ ⠃⠹ ⠹⠑ ⠊⠇⠻⠛⠹⠍⠁⠝⠂ ⠹⠑ ⠊⠇⠻⠅⠂ ⠹⠑ ⠥⠝⠙⠻⠞⠁⠅⠻⠂
⠁⠝⠙ ⠹⠑ ⠡⠊⠑⠋ ⠍⠳⠗⠝⠻⠲ ⡎⠊⠗⠕⠕⠛⠑ ⠎⠊⠛⠝⠫ ⠊⠞⠲ ⡁⠝⠙
⡎⠊⠗⠕⠕⠛⠑⠰⠎ ⠝⠁⠍⠑ ⠺⠁⠎ ⠛⠕⠕⠙ ⠥⠏⠕⠝ ⠰⡡⠁⠝⠛⠑⠂ ⠋⠕⠗ ⠁⠝⠹⠹⠔⠛ ⠙⠑
⠡⠕⠎⠑ ⠞⠕ ⠏⠥⠞ ⠙⠊⠎ ⠙⠁⠝⠙ ⠞⠕⠲
⡕⠇⠙ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
⡍⠔⠙⠖ ⡊ ⠙⠕⠝⠰⠞ ⠍⠑⠁⠝ ⠞⠕ ⠎⠁⠹ ⠹⠁⠞ ⡊ ⠅⠝⠪⠂ ⠕⠋ ⠍⠹
⠪⠝ ⠅⠝⠪⠇⠫⠛⠑⠂ ⠱⠁⠞ ⠹⠻⠑ ⠊⠎ ⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹ ⠙⠑⠁⠙ ⠁⠃⠳⠞
⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ ⡊ ⠍⠊⠣⠞ ⠙⠁⠧⠑ ⠃⠑⠲ ⠔⠊⠇⠔⠫⠂ ⠍⠹⠎⠑⠇⠋⠂ ⠞⠕
⠗⠑⠛⠜⠙ ⠁ ⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇ ⠁⠎ ⠹⠑ ⠙⠑⠁⠙⠑⠌ ⠏⠊⠑⠊⠑ ⠕⠋ ⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹
⠔ ⠹⠑ ⠞⠗⠁⠙⠑⠲ ⡃⠥⠞ ⠹⠑ ⠺⠊⠎⠙⠕⠍ ⠕⠋ ⠳⠗ ⠁⠝⠊⠑⠌⠕⠗⠎
⠊⠎ ⠔ ⠹⠑ ⠎⠊⠍⠊⠇⠑⠆ ⠁⠝⠙ ⠍⠹ ⠥⠝⠙⠁⠇⠇⠪⠫ ⠙⠁⠝⠙⠎
⠩⠁⠇⠇ ⠝⠕⠞ ⠙⠊⠌⠥⠗⠃ ⠊⠞⠂ ⠕⠗ ⠹⠑ ⡊⠳⠝⠞⠗⠹⠰⠎ ⠙⠕⠝⠑ ⠋⠕⠗⠲ ⡹⠳
⠺⠊⠇⠇ ⠹⠻⠑⠋⠕⠗⠑ ⠏⠻⠍⠊⠞ ⠍⠑ ⠞⠕ ⠗⠑⠏⠑⠁⠞⠂ ⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂ ⠹⠁⠞
⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
(The first couple of paragraphs of "A Christmas Carol" by Dickens)
Compact font selection example text:
ABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789
abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ
–—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвгд
∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi<>⑀₂ἠḂӥẄɐː⍎אԱა
Greetings in various languages:
Hello world, Καλημέρα κόσμε, コンニチハ
Box drawing alignment tests: █
╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
╠╡ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
▝▀▘▙▄▟

163
eglib/test/array.c Normal file
View File

@@ -0,0 +1,163 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "test.h"
/* example from glib documentation */
RESULT
test_array_big ()
{
GArray *garray;
gint i;
/* We create a new array to store gint values.
We don't want it zero-terminated or cleared to 0's. */
garray = g_array_new (FALSE, FALSE, sizeof (gint));
for (i = 0; i < 10000; i++)
g_array_append_val (garray, i);
for (i = 0; i < 10000; i++)
if (g_array_index (garray, gint, i) != i)
return FAILED ("array value didn't match");
g_array_free (garray, TRUE);
return NULL;
}
RESULT
test_array_index ()
{
GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
int v;
v = 27;
g_array_append_val (array, v);
if (27 != g_array_index (array, int, 0))
return FAILED ("");
g_array_free (array, TRUE);
return NULL;
}
RESULT
test_array_append_zero_terminated ()
{
GArray *array = g_array_new (TRUE, FALSE, sizeof (int));
int v;
v = 27;
g_array_append_val (array, v);
if (27 != g_array_index (array, int, 0))
return FAILED ("g_array_append_val failed");
if (0 != g_array_index (array, int, 1))
return FAILED ("zero_terminated didn't append a zero element");
g_array_free (array, TRUE);
return NULL;
}
RESULT
test_array_append ()
{
GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
int v;
if (0 != array->len)
return FAILED ("initial array length not zero");
v = 27;
g_array_append_val (array, v);
if (1 != array->len)
return FAILED ("array append failed");
g_array_free (array, TRUE);
return NULL;
}
RESULT
test_array_insert_val ()
{
GArray *array = g_array_new (FALSE, FALSE, sizeof (gpointer));
gpointer ptr0, ptr1, ptr2, ptr3;
g_array_insert_val (array, 0, array);
if (array != g_array_index (array, gpointer, 0))
return FAILED ("1 The value in the array is incorrect");
g_array_insert_val (array, 1, array);
if (array != g_array_index (array, gpointer, 1))
return FAILED ("2 The value in the array is incorrect");
g_array_insert_val (array, 2, array);
if (array != g_array_index (array, gpointer, 2))
return FAILED ("3 The value in the array is incorrect");
g_array_free (array, TRUE);
array = g_array_new (FALSE, FALSE, sizeof (gpointer));
ptr0 = array;
ptr1 = array + 1;
ptr2 = array + 2;
ptr3 = array + 3;
g_array_insert_val (array, 0, ptr0);
g_array_insert_val (array, 1, ptr1);
g_array_insert_val (array, 2, ptr2);
g_array_insert_val (array, 1, ptr3);
if (ptr0 != g_array_index (array, gpointer, 0))
return FAILED ("4 The value in the array is incorrect");
if (ptr3 != g_array_index (array, gpointer, 1))
return FAILED ("5 The value in the array is incorrect");
if (ptr1 != g_array_index (array, gpointer, 2))
return FAILED ("6 The value in the array is incorrect");
if (ptr2 != g_array_index (array, gpointer, 3))
return FAILED ("7 The value in the array is incorrect");
g_array_free (array, TRUE);
return NULL;
}
RESULT
test_array_remove ()
{
GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
int v[] = {30, 29, 28, 27, 26, 25};
g_array_append_vals (array, v, 6);
if (6 != array->len)
return FAILED ("append_vals fail");
g_array_remove_index (array, 3);
if (5 != array->len)
return FAILED ("remove_index failed to update length");
if (26 != g_array_index (array, int, 3))
return FAILED ("remove_index failed to update the array");
g_array_free (array, TRUE);
return NULL;
}
static Test array_tests [] = {
{"big", test_array_big},
{"append", test_array_append},
{"insert_val", test_array_insert_val},
{"index", test_array_index},
{"remove", test_array_remove},
{"append_zero_term", test_array_append_zero_terminated},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(array_tests_init, array_tests)

66
eglib/test/dir.c Normal file
View File

@@ -0,0 +1,66 @@
#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_UNIX
#include <pthread.h>
#endif
#include "test.h"
/* This test is just to be used with valgrind */
RESULT
test_dir ()
{
GDir *dir;
GError *error;
const gchar *name;
/*
dir = g_dir_open (NULL, 0, NULL);
*/
dir = g_dir_open ("", 0, NULL);
if (dir != NULL)
return FAILED ("1 Should be an error");
dir = g_dir_open ("", 9, NULL);
if (dir != NULL)
return FAILED ("2 Should be an error");
error = NULL;
dir = g_dir_open (".ljasdslakjd", 9, &error);
if (dir != NULL)
return FAILED ("3 opendir should fail");
if (error == NULL)
return FAILED ("4 got no error");
g_error_free (error);
error = NULL;
dir = g_dir_open (g_get_tmp_dir (), 9, &error);
if (dir == NULL)
return FAILED ("5 opendir should succeed");
if (error != NULL)
return FAILED ("6 got an error");
name = NULL;
name = g_dir_read_name (dir);
if (name == NULL)
return FAILED ("7 didn't read a file name");
while ((name = g_dir_read_name (dir)) != NULL) {
if (strcmp (name, ".") == 0)
return FAILED (". directory found");
if (strcmp (name, "..") == 0)
return FAILED (".. directory found");
}
g_dir_close (dir);
return OK;
}
static Test dir_tests [] = {
{"g_dir_*", test_dir},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(dir_tests_init, dir_tests)

248
eglib/test/driver.c Normal file
View File

@@ -0,0 +1,248 @@
/*
* EGLib Unit Test Driver
*
* Author:
* Aaron Bockover (abockover@novell.com)
*
* (C) 2006 Novell, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <config.h>
#include "test.h"
#include "tests.h"
#include <stdio.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#ifndef DRIVER_NAME
#define DRIVER_NAME "EGlib"
#endif
typedef struct _StringArray {
gchar **strings;
gint length;
} StringArray;
static StringArray *
string_array_append(StringArray *array, gchar *string)
{
if(array == NULL) {
array = g_new0(StringArray, 1);
array->length = 1;
array->strings = g_malloc(sizeof(gchar *) * 2);
} else {
array->length++;
array->strings = g_realloc(array->strings, sizeof(gchar *)
* (array->length + 1));
}
array->strings[array->length - 1] = string;
array->strings[array->length] = NULL;
return array;
}
gint global_passed = 0, global_tests = 0;
static void
string_array_free(StringArray *array)
{
g_free(array->strings);
g_free(array);
}
static void print_help(char *s)
{
gint i;
printf("Usage: %s [OPTION]... [TESTGROUP]...\n\n", s);
printf("OPTIONS are:\n");
printf(" -h, --help show this help\n");
printf(" -t, --time time the tests\n");
printf(" -i, --iterations number of times to run tests\n");
printf(" -q, --quiet do not print test results; "
"final time always prints\n");
printf(" -n, --no-labels print final time without labels, "
"nice for scripts\n");
printf(" -d, --debug do not run tests, "
"debug the driver itself for valgrind\n\n");
printf("TESTGROUPS available:\n");
for(i = 0; test_groups[i].name != NULL; i++) {
if(test_groups[i].handler != fake_tests_init) {
printf(" %s\n", test_groups[i].name);
}
}
printf("\n");
}
gint main(gint argc, gchar **argv)
{
gint i, j, c, iterations = 1;
StringArray *tests_to_run = NULL;
gdouble time_start;
gboolean report_time = FALSE;
gboolean quiet = FALSE;
gboolean global_failure = FALSE;
gboolean no_final_time_labels = FALSE;
gboolean debug = FALSE;
#if HAVE_GETOPT_H
static struct option long_options [] = {
{"help", no_argument, 0, 'h'},
{"time", no_argument, 0, 't'},
{"quiet", no_argument, 0, 'q'},
{"iterations", required_argument, 0, 'i'},
{"debug", no_argument, 0, 'd'},
{"no-labels", no_argument, 0, 'n'},
{0, 0, 0, 0}
};
while((c = getopt_long(argc, argv, "dhtqni:", long_options, NULL)) != -1) { switch(c) {
case 'h':
print_help(argv[0]);
return 1;
case 't':
report_time = TRUE;
break;
case 'i':
iterations = atoi(optarg);
break;
case 'q':
quiet = TRUE;
break;
case 'n':
no_final_time_labels = TRUE;
break;
case 'd':
debug = TRUE;
break;
}
}
for(i = optind; i < argc; i++) {
if(argv[i][0] == '-') {
continue;
}
tests_to_run = string_array_append(tests_to_run, argv[i]);
}
#endif
time_start = get_timestamp();
for(j = 0; test_groups[j].name != NULL; j++) {
gboolean run = TRUE;
gchar *tests = NULL;
gchar *group = NULL;
if(tests_to_run != NULL) {
gint k;
run = FALSE;
for(k = 0; k < tests_to_run->length; k++) {
gchar *user = tests_to_run->strings[k];
const gchar *table = test_groups[j].name;
size_t user_len = strlen(user);
size_t table_len = strlen(table);
if(strncmp(user, table, table_len) == 0) {
if(user_len > table_len && user[table_len] != ':') {
break;
}
run = TRUE;
group = tests_to_run->strings[k];
break;
}
}
}
if(run) {
gboolean passed;
gchar **split = NULL;
if(debug && test_groups[j].handler != fake_tests_init) {
printf("Skipping %s, in driver debug mode\n",
test_groups[j].name);
continue;
} else if(!debug && test_groups[j].handler == fake_tests_init) {
continue;
}
if(group != NULL) {
split = eg_strsplit(group, ":", -1);
if(split != NULL) {
gint m;
for(m = 0; split[m] != NULL; m++) {
if(m == 1) {
tests = strdup(split[m]);
break;
}
}
eg_strfreev(split);
}
}
passed = run_group(&(test_groups[j]),
iterations, quiet, report_time, tests);
if(tests != NULL) {
g_free(tests);
}
if(!passed && !global_failure) {
global_failure = TRUE;
}
}
}
if(!quiet) {
gdouble pass_percentage = ((gdouble)global_passed / (gdouble)global_tests) * 100.0;
printf("=============================\n");
printf("Overall result: %s : %d / %d (%g%%)\n", global_failure ? "FAILED" : "OK", global_passed, global_tests, pass_percentage);
}
if(report_time) {
gdouble duration = get_timestamp() - time_start;
if(no_final_time_labels) {
printf("%g\n", duration);
} else {
printf("%s Total Time: %g\n", DRIVER_NAME, duration);
}
}
if(tests_to_run != NULL) {
string_array_free(tests_to_run);
}
return global_tests - global_passed;
}

38
eglib/test/endian.c Normal file
View File

@@ -0,0 +1,38 @@
#include "test.h"
RESULT
test_swap ()
{
guint32 a = 0xabcdef01, res32;
guint64 b = (((guint64)a) << 32) | a, res64;
guint64 b_expect = (((guint64)0x1efcdab) << 32) | 0x01efcdab;
guint16 c = 0xabcd, res16;
res32 = GUINT32_SWAP_LE_BE (a);
if (res32 != 0x01efcdab)
return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
res32 = GUINT32_SWAP_LE_BE (1);
if (res32 != 0x1000000)
return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
res64 = GUINT64_SWAP_LE_BE(b);
if (res64 != b_expect)
return FAILED ("GUINT64_SWAP_LE_BE returned 0x%llx (had=0x%llx)", res64, b);
res16 = GUINT16_SWAP_LE_BE(c);
if (res16 != 0xcdab)
return FAILED ("GUINT16_SWAP_LE_BE returned 0x%x", (guint32) res16);
return OK;
}
/*
* test initialization
*/
static Test endian_tests [] = {
{"swap", test_swap},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(endian_tests_init, endian_tests)

19
eglib/test/fake.c Normal file
View File

@@ -0,0 +1,19 @@
/*
* Fake test allows debugging of the driver itself
*/
#include "test.h"
RESULT
test_fake()
{
return OK;
}
static Test fake_tests [] = {
{"fake", test_fake},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(fake_tests_init, fake_tests)

228
eglib/test/file.c Normal file
View File

@@ -0,0 +1,228 @@
#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdio.h>
#include "test.h"
#ifdef G_OS_WIN32
#include <io.h>
#define close _close
#endif
RESULT
test_file_get_contents ()
{
GError *error;
gchar *content;
gboolean ret;
gsize length;
#ifdef G_OS_WIN32
const gchar *filename = "c:\\Windows\\system.ini";
#else
const gchar *filename = "/etc/hosts";
#endif
/*
filename != NULL
ret = g_file_get_contents (NULL, NULL, NULL, NULL);
contents != NULL
ret = g_file_get_contents ("", NULL, NULL, NULL);
error no such file and fails for 'error' not being null too
ret = g_file_get_contents ("", &content, NULL, &error);
*/
error = NULL;
ret = g_file_get_contents ("", &content, NULL, &error);
if (ret)
return FAILED ("HAH!");
if (error == NULL)
return FAILED ("Got nothing as error.");
if (content != NULL)
return FAILED ("Content is uninitialized");
g_error_free (error);
error = NULL;
ret = g_file_get_contents (filename, &content, &length, &error);
if (!ret)
return FAILED ("The error is %d %s\n", error->code, error->message);
if (error != NULL)
return FAILED ("Got an error returning TRUE");
if (content == NULL)
return FAILED ("Content is NULL");
if (strlen (content) != length)
return FAILED ("length is %d but the string is %d", length, strlen (content));
g_free (content);
return OK;
}
RESULT
test_open_tmp ()
{
GError *error;
gint fd;
gchar *name = GINT_TO_POINTER (-1);
/*
* Okay, this works, but creates a .xxx file in /tmp on every run. Disabled.
* fd = g_file_open_tmp (NULL, NULL, NULL);
* if (fd < 0)
* return FAILED ("Default failed.");
* close (fd);
*/
error = NULL;
fd = g_file_open_tmp ("invalidtemplate", NULL, &error);
if (fd != -1)
return FAILED ("The template was invalid and accepted");
if (error == NULL)
return FAILED ("No error returned.");
g_error_free (error);
error = NULL;
fd = g_file_open_tmp ("i/nvalidtemplate", &name, &error);
if (fd != -1)
return FAILED ("The template was invalid and accepted");
if (error == NULL)
return FAILED ("No error returned.");
if (name == NULL)
return FAILED ("'name' is not reset");
g_error_free (error);
error = NULL;
fd = g_file_open_tmp ("valid-XXXXXX", &name, &error);
if (fd == -1)
return FAILED ("This should be valid");
if (error != NULL)
return FAILED ("No error returned.");
if (name == NULL)
return FAILED ("No name returned.");
close (fd);
unlink (name);
g_free (name);
return OK;
}
RESULT
test_file ()
{
gboolean res;
const gchar *tmp;
gchar *path;
#ifndef G_OS_WIN32 /* FIXME */
gchar *sympath;
gint ignored;
#endif
res = g_file_test (NULL, 0);
if (res)
return FAILED ("Should return FALSE HERE");
res = g_file_test ("file.c", 0);
if (res)
return FAILED ("Should return FALSE HERE");
tmp = g_get_tmp_dir ();
res = g_file_test (tmp, G_FILE_TEST_EXISTS);
if (!res)
return FAILED ("tmp does not exist.");
res = g_file_test (tmp, G_FILE_TEST_IS_REGULAR);
if (res)
return FAILED ("tmp is regular");
res = g_file_test (tmp, G_FILE_TEST_IS_DIR);
if (!res)
return FAILED ("tmp is not a directory");
res = g_file_test (tmp, G_FILE_TEST_IS_EXECUTABLE);
if (!res)
return FAILED ("tmp is not a executable");
res = g_file_test (tmp, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK);
if (!res)
return FAILED ("2 tmp does not exist.");
res = g_file_test (tmp, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK);
if (res)
return FAILED ("2 tmp is regular");
res = g_file_test (tmp, G_FILE_TEST_IS_DIR | G_FILE_TEST_IS_SYMLINK);
if (!res)
return FAILED ("2 tmp is not a directory");
res = g_file_test (tmp, G_FILE_TEST_IS_EXECUTABLE | G_FILE_TEST_IS_SYMLINK);
if (!res)
return FAILED ("2 tmp is not a executable");
close (g_file_open_tmp (NULL, &path, NULL)); /* create an empty file */
res = g_file_test (path, G_FILE_TEST_EXISTS);
if (!res)
return FAILED ("3 %s should exist", path);
res = g_file_test (path, G_FILE_TEST_IS_REGULAR);
/* This is strange. Empty file is reported as not existing! */
if (!res)
return FAILED ("3 %s IS_REGULAR", path);
res = g_file_test (path, G_FILE_TEST_IS_DIR);
if (res)
return FAILED ("3 %s should not be a directory", path);
res = g_file_test (path, G_FILE_TEST_IS_EXECUTABLE);
if (res)
return FAILED ("3 %s should not be executable", path);
res = g_file_test (path, G_FILE_TEST_IS_SYMLINK);
if (res)
return FAILED ("3 %s should not be a symlink", path);
#ifndef G_OS_WIN32 /* FIXME */
sympath = g_strconcat (path, "-link", NULL);
ignored = symlink (path, sympath);
res = g_file_test (sympath, G_FILE_TEST_EXISTS);
if (!res)
return FAILED ("4 %s should not exist", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_REGULAR);
if (!res)
return FAILED ("4 %s should not be a regular file", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_DIR);
if (res)
return FAILED ("4 %s should not be a directory", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_EXECUTABLE);
if (res)
return FAILED ("4 %s should not be executable", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_SYMLINK);
if (!res)
return FAILED ("4 %s should be a symlink", sympath);
unlink (path);
res = g_file_test (sympath, G_FILE_TEST_EXISTS);
if (res)
return FAILED ("5 %s should exist", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_REGULAR);
if (res)
return FAILED ("5 %s should be a regular file", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_DIR);
if (res)
return FAILED ("5 %s should not be a directory", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_EXECUTABLE);
if (res)
return FAILED ("5 %s should not be executable", sympath);
res = g_file_test (sympath, G_FILE_TEST_IS_SYMLINK);
if (!res)
return FAILED ("5 %s should be a symlink", sympath);
unlink (sympath);
g_free (sympath);
#endif
g_free (path);
return OK;
}
static Test file_tests [] = {
{"g_file_get_contents", test_file_get_contents},
{"g_file_open_tmp", test_open_tmp},
{"g_file_test", test_file},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(file_tests_init, file_tests)

177
eglib/test/hashtable.c Normal file
View File

@@ -0,0 +1,177 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "test.h"
int foreach_count = 0;
int foreach_fail = 0;
void foreach (gpointer key, gpointer value, gpointer user_data)
{
foreach_count++;
if (GPOINTER_TO_INT (user_data) != 'a')
foreach_fail = 1;
}
RESULT hash_t1 (void)
{
GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
foreach_count = 0;
foreach_fail = 0;
g_hash_table_insert (t, "hello", "world");
g_hash_table_insert (t, "my", "god");
g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
if (foreach_count != 2)
return FAILED ("did not find all keys, got %d expected 2", foreach_count);
if (foreach_fail)
return FAILED("failed to pass the user-data to foreach");
if (!g_hash_table_remove (t, "my"))
return FAILED ("did not find known key");
if (g_hash_table_size (t) != 1)
return FAILED ("unexpected size");
g_hash_table_insert(t, "hello", "moon");
if (strcmp (g_hash_table_lookup (t, "hello"), "moon") != 0)
return FAILED ("did not replace world with moon");
if (!g_hash_table_remove (t, "hello"))
return FAILED ("did not find known key");
if (g_hash_table_size (t) != 0)
return FAILED ("unexpected size");
g_hash_table_destroy (t);
return OK;
}
RESULT hash_t2 (void)
{
return OK;
}
RESULT hash_default (void)
{
GHashTable *hash = g_hash_table_new (NULL, NULL);
if (hash == NULL)
return FAILED ("g_hash_table_new should return a valid hash");
g_hash_table_destroy (hash);
return NULL;
}
RESULT
hash_null_lookup (void)
{
GHashTable *hash = g_hash_table_new (NULL, NULL);
gpointer ok, ov;
g_hash_table_insert (hash, NULL, GINT_TO_POINTER (1));
g_hash_table_insert (hash, GINT_TO_POINTER(1), GINT_TO_POINTER(2));
if (!g_hash_table_lookup_extended (hash, NULL, &ok, &ov))
return FAILED ("Did not find the NULL");
if (ok != NULL)
return FAILED ("Incorrect key found");
if (ov != GINT_TO_POINTER (1))
return FAILED ("Got wrong value %p\n", ov);
if (!g_hash_table_lookup_extended (hash, GINT_TO_POINTER(1), &ok, &ov))
return FAILED ("Did not find the 1");
if (ok != GINT_TO_POINTER(1))
return FAILED ("Incorrect key found");
if (ov != GINT_TO_POINTER (2))
return FAILED ("Got wrong value %p\n", ov);
g_hash_table_destroy (hash);
return NULL;
}
static void
counter (gpointer key, gpointer value, gpointer user_data)
{
int *counter = (int *) user_data;
(*counter)++;
}
RESULT hash_grow (void)
{
GHashTable *hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
int i, count = 0;
for (i = 0; i < 1000; i++)
g_hash_table_insert (hash, g_strdup_printf ("%d", i), g_strdup_printf ("x-%d", i));
for (i = 0; i < 1000; i++){
char buffer [30];
gpointer value;
sprintf (buffer, "%d", i);
value = g_hash_table_lookup (hash, buffer);
sprintf (buffer, "x-%d", i);
if (strcmp (value, buffer) != 0){
return FAILED ("Failed to lookup the key %d, the value was %s\n", i, value);
}
}
if (g_hash_table_size (hash) != 1000)
return FAILED ("Did not find 1000 elements on the hash, found %d\n", g_hash_table_size (hash));
/* Now do the manual count, lets not trust the internals */
g_hash_table_foreach (hash, counter, &count);
if (count != 1000){
return FAILED ("Foreach count is not 1000");
}
g_hash_table_destroy (hash);
return NULL;
}
RESULT hash_iter (void)
{
#if !defined(GLIB_MAJOR_VERSION) || GLIB_CHECK_VERSION(2, 16, 0)
GHashTable *hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL);
GHashTableIter iter;
int i, sum, keys_sum, values_sum;
gpointer key, value;
sum = 0;
for (i = 0; i < 1000; i++) {
sum += i;
g_hash_table_insert (hash, GUINT_TO_POINTER (i), GUINT_TO_POINTER (i));
}
keys_sum = values_sum = 0;
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, &key, &value)) {
if (key != value)
return FAILED ("key != value");
keys_sum += GPOINTER_TO_UINT (key);
values_sum += GPOINTER_TO_UINT (value);
}
if (keys_sum != sum || values_sum != sum)
return FAILED ("Did not find all key-value pairs");
g_hash_table_destroy (hash);
return NULL;
#else
/* GHashTableIter was added in glib 2.16 */
return NULL;
#endif
}
static Test hashtable_tests [] = {
{"t1", hash_t1},
{"t2", hash_t2},
{"grow", hash_grow},
{"default", hash_default},
{"null_lookup", hash_null_lookup},
{"iter", hash_iter},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(hashtable_tests_init, hashtable_tests)

438
eglib/test/list.c Normal file
View File

@@ -0,0 +1,438 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "test.h"
RESULT
test_list_length ()
{
GList *list = g_list_prepend (NULL, "foo");
if (g_list_length (list) != 1)
return FAILED ("length failed. #1");
list = g_list_prepend (list, "bar");
if (g_list_length (list) != 2)
return FAILED ("length failed. #2");
list = g_list_append (list, "bar");
if (g_list_length (list) != 3)
return FAILED ("length failed. #3");
g_list_free (list);
return NULL;
}
RESULT
test_list_nth ()
{
char *foo = "foo";
char *bar = "bar";
char *baz = "baz";
GList *nth, *list;
list = g_list_prepend (NULL, baz);
list = g_list_prepend (list, bar);
list = g_list_prepend (list, foo);
nth = g_list_nth (list, 0);
if (nth->data != foo)
return FAILED ("nth failed. #0");
nth = g_list_nth (list, 1);
if (nth->data != bar)
return FAILED ("nth failed. #1");
nth = g_list_nth (list, 2);
if (nth->data != baz)
return FAILED ("nth failed. #2");
nth = g_list_nth (list, 3);
if (nth)
return FAILED ("nth failed. #3: %s", nth->data);
g_list_free (list);
return OK;
}
RESULT
test_list_index ()
{
int i;
char *foo = "foo";
char *bar = "bar";
char *baz = "baz";
GList *list;
list = g_list_prepend (NULL, baz);
list = g_list_prepend (list, bar);
list = g_list_prepend (list, foo);
i = g_list_index (list, foo);
if (i != 0)
return FAILED ("index failed. #0: %d", i);
i = g_list_index (list, bar);
if (i != 1)
return FAILED ("index failed. #1: %d", i);
i = g_list_index (list, baz);
if (i != 2)
return FAILED ("index failed. #2: %d", i);
g_list_free (list);
return OK;
}
RESULT
test_list_append ()
{
GList *list = g_list_prepend (NULL, "first");
if (g_list_length (list) != 1)
return FAILED ("Prepend failed");
list = g_list_append (list, "second");
if (g_list_length (list) != 2)
return FAILED ("Append failed");
g_list_free (list);
return OK;
}
RESULT
test_list_last ()
{
GList *foo = g_list_prepend (NULL, "foo");
GList *bar = g_list_prepend (NULL, "bar");
GList *last;
foo = g_list_concat (foo, bar);
last = g_list_last (foo);
if (last != bar)
return FAILED ("last failed. #1");
foo = g_list_concat (foo, g_list_prepend (NULL, "baz"));
foo = g_list_concat (foo, g_list_prepend (NULL, "quux"));
last = g_list_last (foo);
if (strcmp ("quux", last->data))
return FAILED ("last failed. #2");
g_list_free (foo);
return OK;
}
RESULT
test_list_concat ()
{
GList *foo = g_list_prepend (NULL, "foo");
GList *bar = g_list_prepend (NULL, "bar");
GList *list = g_list_concat (foo, bar);
if (g_list_length (list) != 2)
return FAILED ("Concat failed. #1");
if (strcmp (list->data, "foo"))
return FAILED ("Concat failed. #2");
if (strcmp (list->next->data, "bar"))
return FAILED ("Concat failed. #3");
if (g_list_first (list) != foo)
return FAILED ("Concat failed. #4");
if (g_list_last (list) != bar)
return FAILED ("Concat failed. #5");
g_list_free (list);
return OK;
}
static gint
compare (gconstpointer a, gconstpointer b)
{
char *foo = (char *) a;
char *bar = (char *) b;
if (strlen (foo) < strlen (bar))
return -1;
return 1;
}
RESULT
test_list_insert_sorted ()
{
GList *list = g_list_prepend (NULL, "a");
list = g_list_append (list, "aaa");
/* insert at the middle */
list = g_list_insert_sorted (list, "aa", compare);
if (strcmp ("aa", list->next->data))
return FAILED ("insert_sorted failed. #1");
/* insert at the beginning */
list = g_list_insert_sorted (list, "", compare);
if (strcmp ("", list->data))
return FAILED ("insert_sorted failed. #2");
/* insert at the end */
list = g_list_insert_sorted (list, "aaaa", compare);
if (strcmp ("aaaa", g_list_last (list)->data))
return FAILED ("insert_sorted failed. #3");
g_list_free (list);
return OK;
}
RESULT
test_list_copy ()
{
int i, length;
GList *list, *copy;
list = g_list_prepend (NULL, "a");
list = g_list_append (list, "aa");
list = g_list_append (list, "aaa");
list = g_list_append (list, "aaaa");
length = g_list_length (list);
copy = g_list_copy (list);
for (i = 0; i < length; i++)
if (strcmp (g_list_nth (list, i)->data,
g_list_nth (copy, i)->data))
return FAILED ("copy failed.");
g_list_free (list);
g_list_free (copy);
return OK;
}
RESULT
test_list_reverse ()
{
guint i, length;
GList *list, *reverse;
list = g_list_prepend (NULL, "a");
list = g_list_append (list, "aa");
list = g_list_append (list, "aaa");
list = g_list_append (list, "aaaa");
length = g_list_length (list);
reverse = g_list_reverse (g_list_copy (list));
if (g_list_length (reverse) != length)
return FAILED ("reverse failed #1");
for (i = 0; i < length; i++){
guint j = length - i - 1;
if (strcmp (g_list_nth (list, i)->data,
g_list_nth (reverse, j)->data))
return FAILED ("reverse failed. #2");
}
g_list_free (list);
g_list_free (reverse);
return OK;
}
RESULT
test_list_remove ()
{
GList *list = g_list_prepend (NULL, "three");
char *one = "one";
list = g_list_prepend (list, "two");
list = g_list_prepend (list, one);
list = g_list_remove (list, one);
if (g_list_length (list) != 2)
return FAILED ("Remove failed");
if (strcmp ("two", list->data) != 0)
return FAILED ("Remove failed");
g_list_free (list);
return OK;
}
RESULT
test_list_remove_link ()
{
GList *foo = g_list_prepend (NULL, "a");
GList *bar = g_list_prepend (NULL, "b");
GList *baz = g_list_prepend (NULL, "c");
GList *list = foo;
foo = g_list_concat (foo, bar);
foo = g_list_concat (foo, baz);
list = g_list_remove_link (list, bar);
if (g_list_length (list) != 2)
return FAILED ("remove_link failed #1");
if (bar->next != NULL)
return FAILED ("remove_link failed #2");
g_list_free (list);
g_list_free (bar);
return OK;
}
RESULT
test_list_insert_before ()
{
GList *foo, *bar, *baz;
foo = g_list_prepend (NULL, "foo");
foo = g_list_insert_before (foo, NULL, "bar");
bar = g_list_last (foo);
if (strcmp (bar->data, "bar"))
return FAILED ("1");
baz = g_list_insert_before (foo, bar, "baz");
if (foo != baz)
return FAILED ("2");
if (strcmp (g_list_nth_data (foo, 1), "baz"))
return FAILED ("3: %s", g_list_nth_data (foo, 1));
g_list_free (foo);
return OK;
}
#define N_ELEMS 101
static int intcompare (gconstpointer p1, gconstpointer p2)
{
return GPOINTER_TO_INT (p1) - GPOINTER_TO_INT (p2);
}
static gboolean verify_sort (GList *list, int len)
{
int prev;
if (list->prev)
return FALSE;
prev = GPOINTER_TO_INT (list->data);
len--;
for (list = list->next; list; list = list->next) {
int curr = GPOINTER_TO_INT (list->data);
if (prev > curr)
return FALSE;
prev = curr;
if (!list->prev || list->prev->next != list)
return FALSE;
if (len == 0)
return FALSE;
len--;
}
return len == 0;
}
RESULT
test_list_sort ()
{
int i, j, mul;
GList *list = NULL;
for (i = 0; i < N_ELEMS; ++i)
list = g_list_prepend (list, GINT_TO_POINTER (i));
list = g_list_sort (list, intcompare);
if (!verify_sort (list, N_ELEMS))
return FAILED ("decreasing list");
g_list_free (list);
list = NULL;
for (i = 0; i < N_ELEMS; ++i)
list = g_list_prepend (list, GINT_TO_POINTER (-i));
list = g_list_sort (list, intcompare);
if (!verify_sort (list, N_ELEMS))
return FAILED ("increasing list");
g_list_free (list);
list = g_list_prepend (NULL, GINT_TO_POINTER (0));
for (i = 1; i < N_ELEMS; ++i) {
list = g_list_prepend (list, GINT_TO_POINTER (i));
list = g_list_prepend (list, GINT_TO_POINTER (-i));
}
list = g_list_sort (list, intcompare);
if (!verify_sort (list, 2*N_ELEMS-1))
return FAILED ("alternating list");
g_list_free (list);
list = NULL;
mul = 1;
for (i = 1; i < N_ELEMS; ++i) {
mul = -mul;
for (j = 0; j < i; ++j)
list = g_list_prepend (list, GINT_TO_POINTER (mul * j));
}
list = g_list_sort (list, intcompare);
if (!verify_sort (list, (N_ELEMS*N_ELEMS - N_ELEMS)/2))
return FAILED ("wavering list");
g_list_free (list);
return OK;
}
static gint
find_custom (gconstpointer a, gconstpointer b)
{
return(strcmp (a, b));
}
RESULT
test_list_find_custom ()
{
GList *list = NULL, *found;
char *foo = "foo";
char *bar = "bar";
char *baz = "baz";
list = g_list_prepend (list, baz);
list = g_list_prepend (list, bar);
list = g_list_prepend (list, foo);
found = g_list_find_custom (list, baz, find_custom);
if (found == NULL)
return FAILED ("Find failed");
g_list_free (list);
return OK;
}
static Test list_tests [] = {
{ "length", test_list_length},
{ "nth", test_list_nth},
{ "index", test_list_index},
{ "last", test_list_last},
{ "append", test_list_append},
{ "concat", test_list_concat},
{"insert_sorted", test_list_insert_sorted},
{"insert_before", test_list_insert_before},
{ "copy", test_list_copy},
{ "reverse", test_list_reverse},
{ "remove", test_list_remove},
{ "remove_link", test_list_remove_link},
{ "remove_link", test_list_remove_link},
{ "sort", test_list_sort},
{ "find_custom", test_list_find_custom},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(list_tests_init, list_tests)

234
eglib/test/markup.c Normal file
View File

@@ -0,0 +1,234 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "test.h"
#define do_bad_test(s) do { char *r = markup_test (s); if (r == NULL) return FAILED ("Failed on test " # s); else g_free (r); } while (0)
#define do_ok_test(s) do { char *r = markup_test (s); if (r != NULL) return FAILED ("Could not parse valid " # s); } while (0)
static char *
markup_test (const char *s)
{
GMarkupParser *parser = g_new0 (GMarkupParser, 1);
GMarkupParseContext *context;
GError *error = NULL;
context = g_markup_parse_context_new (parser, 0, 0, 0);
g_markup_parse_context_parse (context, s, strlen (s), &error);
g_markup_parse_context_free (context);
if (error != NULL){
char *msg = g_strdup (error->message);
g_error_free (error);
g_free (parser);
return msg;
}
g_free (parser);
return NULL;
}
RESULT
invalid_documents (void)
{
/* These should fail */
do_bad_test ("<1>");
do_bad_test ("<a<");
do_bad_test ("</a>");
do_bad_test ("<a b>");
do_bad_test ("<a b=>");
do_bad_test ("<a b=c>");
return OK;
}
RESULT
valid_documents (void)
{
/* These should fail */
do_ok_test ("<a>");
do_ok_test ("<a a=\"b\">");
return OK;
}
/*
* This is a test for the kind of files that the code in mono/domain.c
* parses; This code comes from Mono
*/
typedef struct {
GSList *supported_runtimes;
char *required_runtime;
int configuration_count;
int startup_count;
} AppConfigInfo;
static char *
get_attribute_value (const gchar **attribute_names,
const gchar **attribute_values,
const char *att_name)
{
int n;
for (n=0; attribute_names[n] != NULL; n++) {
if (strcmp (attribute_names[n], att_name) == 0)
return g_strdup (attribute_values[n]);
}
return NULL;
}
static void
start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
AppConfigInfo* app_config = (AppConfigInfo*) user_data;
if (strcmp (element_name, "configuration") == 0) {
app_config->configuration_count++;
return;
}
if (strcmp (element_name, "startup") == 0) {
app_config->startup_count++;
return;
}
if (app_config->configuration_count != 1 || app_config->startup_count != 1)
return;
if (strcmp (element_name, "requiredRuntime") == 0) {
app_config->required_runtime = get_attribute_value (attribute_names, attribute_values, "version");
} else if (strcmp (element_name, "supportedRuntime") == 0) {
char *version = get_attribute_value (attribute_names, attribute_values, "version");
app_config->supported_runtimes = g_slist_append (app_config->supported_runtimes, version);
}
}
static void
end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error)
{
AppConfigInfo* app_config = (AppConfigInfo*) user_data;
if (strcmp (element_name, "configuration") == 0) {
app_config->configuration_count--;
} else if (strcmp (element_name, "startup") == 0) {
app_config->startup_count--;
}
}
static const GMarkupParser
mono_parser = {
start_element,
end_element,
NULL,
NULL,
NULL
};
AppConfigInfo *
domain_test (char *text)
{
AppConfigInfo *app_config = g_new0 (AppConfigInfo, 1);
GMarkupParseContext *context;
context = g_markup_parse_context_new (&mono_parser, 0, app_config, NULL);
if (g_markup_parse_context_parse (context, text, strlen (text), NULL)) {
g_markup_parse_context_end_parse (context, NULL);
}
g_markup_parse_context_free (context);
return app_config;
}
void
domain_free (AppConfigInfo *info)
{
GSList *l;
if (info->required_runtime)
g_free (info->required_runtime);
for (l = info->supported_runtimes; l != NULL; l = l->next){
g_free (l->data);
}
g_slist_free (info->supported_runtimes);
g_free (info);
}
RESULT
mono_domain (void)
{
AppConfigInfo *info;
info = domain_test ("<configuration><!--hello--><startup><!--world--><requiredRuntime version=\"v1\"><!--r--></requiredRuntime></startup></configuration>");
if (info->required_runtime == NULL)
return FAILED ("No required runtime section");
if (strcmp (info->required_runtime, "v1") != 0)
return FAILED ("Got a runtime version %s, expected v1", info->required_runtime);
domain_free (info);
info = domain_test ("<configuration><startup><requiredRuntime version=\"v1\"/><!--comment--></configuration><!--end-->");
if (info->required_runtime == NULL)
return FAILED ("No required runtime section on auto-close section");
if (strcmp (info->required_runtime, "v1") != 0)
return FAILED ("Got a runtime version %s, expected v1", info->required_runtime);
domain_free (info);
info = domain_test ("<!--start--><configuration><startup><supportedRuntime version=\"v1\"/><!--middle--><supportedRuntime version=\"v2\"/></startup></configuration>");
if ((strcmp ((char*)info->supported_runtimes->data, "v1") == 0)){
if (info->supported_runtimes->next == NULL)
return FAILED ("Expected 2 supported runtimes");
if ((strcmp ((char*)info->supported_runtimes->next->data, "v2") != 0))
return FAILED ("Expected v1, v2, got %s", info->supported_runtimes->next->data);
if (info->supported_runtimes->next->next != NULL)
return FAILED ("Expected v1, v2, got more");
} else
return FAILED ("Expected `v1', got %s", info->supported_runtimes->data);
domain_free (info);
return NULL;
}
RESULT
mcs_config (void)
{
return markup_test ("<configuration>\r\n <system.diagnostics>\r\n <trace autoflush=\"true\" indentsize=\"4\">\r\n <listeners>\r\n <add name=\"compilerLogListener\" type=\"System.Diagnostics.TextWriterTraceListener,System\"/> </listeners> </trace> </system.diagnostics> </configuration>");
}
RESULT
xml_parse (void)
{
return markup_test ("<?xml version=\"1.0\" encoding=\"utf-8\"?><a></a>");
}
RESULT
machine_config (void)
{
char *data;
gsize size;
if (g_file_get_contents ("../../data/net_1_1/machine.config", &data, &size, NULL)){
return markup_test (data);
}
printf ("Ignoring this test\n");
return NULL;
}
static Test markup_tests [] = {
{"invalid_documents", invalid_documents},
{"good_documents", valid_documents},
{"mono_domain", mono_domain},
{"mcs_config", mcs_config},
{"xml_parse", xml_parse},
{"machine_config", machine_config},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(markup_tests_init, markup_tests)

40
eglib/test/memory.c Normal file
View File

@@ -0,0 +1,40 @@
#include <glib.h>
#include "test.h"
RESULT
test_memory_zero_size_allocations ()
{
gpointer p;
p = g_malloc (0);
if (p)
return FAILED ("Calling g_malloc with size zero should return NULL.");
p = g_malloc0 (0);
if (p)
return FAILED ("Calling g_malloc0 with size zero should return NULL.");
p = g_realloc (NULL, 0);
if (p)
return FAILED ("Calling g_realloc with size zero should return NULL.");
p = g_new (int, 0);
if (p)
return FAILED ("Calling g_new with size zero should return NULL.");
p = g_new0 (int, 0);
if (p)
return FAILED ("Calling g_new0 with size zero should return NULL.");
return OK;
}
static Test memory_tests [] = {
{ "zero_size_allocations", test_memory_zero_size_allocations},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(memory_tests_init, memory_tests)

64
eglib/test/module.c Normal file
View File

@@ -0,0 +1,64 @@
#include <config.h>
#include <glib.h>
#include <gmodule.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "test.h"
#if defined (G_OS_WIN32)
#define EXTERNAL_SYMBOL "GetProcAddress"
#else
#define EXTERNAL_SYMBOL "system"
#endif
void G_MODULE_EXPORT
dummy_test_export ()
{
}
/* test for g_module_open (NULL, ...) */
RESULT
test_module_symbol_null ()
{
gpointer proc = GINT_TO_POINTER (42);
GModule *m = g_module_open (NULL, G_MODULE_BIND_LAZY);
if (m == NULL)
return FAILED ("bind to main module failed. #0");
if (g_module_symbol (m, "__unlikely_\nexistent__", &proc))
return FAILED ("non-existent symbol lookup failed. #1");
if (proc)
return FAILED ("non-existent symbol lookup failed. #2");
if (!g_module_symbol (m, EXTERNAL_SYMBOL, &proc))
return FAILED ("external lookup failed. #3");
if (!proc)
return FAILED ("external lookup failed. #4");
if (!g_module_symbol (m, "dummy_test_export", &proc))
return FAILED ("in-proc lookup failed. #5");
if (!proc)
return FAILED ("in-proc lookup failed. #6");
if (!g_module_close (m))
return FAILED ("close failed. #7");
return OK;
}
static Test module_tests [] = {
{"g_module_symbol_null", test_module_symbol_null},
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(module_tests_init, module_tests)

357
eglib/test/path.c Normal file
View File

@@ -0,0 +1,357 @@
#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_UNIX
#include <pthread.h>
#endif
#include "test.h"
#ifdef G_OS_WIN32
#include <direct.h>
#define chdir _chdir
#endif
/* This test is just to be used with valgrind */
RESULT
test_buildpath ()
{
char *s;
char *buffer = "var/private";
char *dir = "/";
s = g_build_path ("/", "hola///", "//mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("1 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola/", "/mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("2 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola/", "mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("3 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola", "/mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("4 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "/hello", "world/", NULL);
if (strcmp (s, "/hello/world/") != 0)
return FAILED ("5 Got wrong result, got: %s", s);
g_free (s);
/* Now test multi-char-separators */
s = g_build_path ("**", "hello", "world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("6 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("7 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "**world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("8 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "**world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("9 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello", "world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("10 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello1234567890", "1234567890world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("11 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello12345678901234567890", "1234567890world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("12 Got wrong result, got: %s", s);
g_free (s);
/* Multiple */
s = g_build_path ("/", "a", "b", "c", "d", NULL);
if (strcmp (s, "a/b/c/d") != 0)
return FAILED ("13 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "/a", "", "/c/", NULL);
if (strcmp (s, "/a/c/") != 0)
return FAILED ("14 Got wrong result, got: %s", s);
g_free (s);
/* Null */
s = g_build_path ("/", NULL, NULL);
if (s == NULL)
return FAILED ("must get a non-NULL return");
if (s [0] != 0)
return FAILED ("must get an empty string");
// This is to test the regression introduced by Levi for the Windows support
// that code errouneously read below the allowed area (in this case dir [-1]).
// and caused all kinds of random errors.
dir = "//";
dir++;
s = g_build_filename (dir, buffer, NULL);
if (s [0] != '/')
return FAILED ("Must have a '/' at the start");
g_free (s);
return OK;
}
RESULT
test_buildfname ()
{
char *s;
s = g_build_filename ("a", "b", "c", "d", NULL);
#ifdef G_OS_WIN32
if (strcmp (s, "a\\b\\c\\d") != 0)
#else
if (strcmp (s, "a/b/c/d") != 0)
#endif
return FAILED ("1 Got wrong result, got: %s", s);
g_free (s);
#ifdef G_OS_WIN32
s = g_build_filename ("C:\\", "a", NULL);
if (strcmp (s, "C:\\a") != 0)
#else
s = g_build_filename ("/", "a", NULL);
if (strcmp (s, "/a") != 0)
#endif
return FAILED ("1 Got wrong result, got: %s", s);
#ifndef G_OS_WIN32
s = g_build_filename ("/", "foo", "/bar", "tolo/", "/meo/", NULL);
if (strcmp (s, "/foo/bar/tolo/meo/") != 0)
return FAILED ("1 Got wrong result, got: %s", s);
#endif
return OK;
}
char *
test_dirname ()
{
char *s;
#ifdef G_OS_WIN32
s = g_path_get_dirname ("c:\\home\\miguel");
if (strcmp (s, "c:\\home") != 0)
return FAILED ("Expected c:\\home, got %s", s);
g_free (s);
s = g_path_get_dirname ("c:/home/miguel");
if (strcmp (s, "c:/home") != 0)
return FAILED ("Expected c:/home, got %s", s);
g_free (s);
s = g_path_get_dirname ("c:\\home\\dingus\\");
if (strcmp (s, "c:\\home\\dingus") != 0)
return FAILED ("Expected c:\\home\\dingus, got %s", s);
g_free (s);
s = g_path_get_dirname ("dir.c");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_dirname ("c:\\index.html");
if (strcmp (s, "c:") != 0)
return FAILED ("Expected [c:], got [%s]", s);
#else
s = g_path_get_dirname ("/home/miguel");
if (strcmp (s, "/home") != 0)
return FAILED ("Expected /home, got %s", s);
g_free (s);
s = g_path_get_dirname ("/home/dingus/");
if (strcmp (s, "/home/dingus") != 0)
return FAILED ("Expected /home/dingus, got %s", s);
g_free (s);
s = g_path_get_dirname ("dir.c");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_dirname ("/index.html");
if (strcmp (s, "/") != 0)
return FAILED ("Expected [/], got [%s]", s);
#endif
return OK;
}
char *
test_basename ()
{
char *s;
#ifdef G_OS_WIN32
s = g_path_get_basename ("");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_basename ("c:\\home\\dingus\\");
if (strcmp (s, "dingus") != 0)
return FAILED ("1 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("c:/home/dingus/");
if (strcmp (s, "dingus") != 0)
return FAILED ("1 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("c:\\home\\dingus");
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("c:/home/dingus");
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
#else
s = g_path_get_basename ("");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_basename ("/home/dingus/");
if (strcmp (s, "dingus") != 0)
return FAILED ("1 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("/home/dingus");
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
#endif
return OK;
}
gchar *
test_ppath ()
{
char *s;
#ifdef G_OS_WIN32
const gchar *searchfor = "explorer.exe";
#else
const gchar *searchfor = "ls";
#endif
s = g_find_program_in_path (searchfor);
if (s == NULL)
return FAILED ("No %s on this system?", searchfor);
g_free (s);
return OK;
}
gchar *
test_ppath2 ()
{
char *s;
const char *path = g_getenv ("PATH");
#ifdef G_OS_WIN32
const gchar *searchfor = "test_eglib.exe";
#else
const gchar *searchfor = "test-glib";
#endif
g_setenv ("PATH", "", TRUE);
s = g_find_program_in_path ("ls");
if (s != NULL) {
g_setenv ("PATH", path, TRUE);
return FAILED ("Found something interesting here: %s", s);
}
g_free (s);
s = g_find_program_in_path (searchfor);
if (s == NULL) {
g_setenv ("PATH", path, TRUE);
return FAILED ("It should find '%s' in the current directory.", searchfor);
}
g_free (s);
g_setenv ("PATH", path, TRUE);
return OK;
}
#ifndef DISABLE_FILESYSTEM_TESTS
gchar *
test_cwd ()
{
char *dir = g_get_current_dir ();
#ifdef G_OS_WIN32
const gchar *newdir = "C:\\Windows";
#else
const gchar *newdir = "/bin";
#endif
if (dir == NULL)
return FAILED ("No current directory?");
g_free (dir);
if (chdir (newdir) == -1)
return FAILED ("No %s?", newdir);
dir = g_get_current_dir ();
if (strcmp (dir, newdir) != 0)
return FAILED("Did not go to %s?", newdir);
g_free (dir);
return OK;
}
#else
gchar *
test_cwd ()
{
return OK;
}
#endif
gchar *
test_misc ()
{
const char *home = g_get_home_dir ();
const char *tmp = g_get_tmp_dir ();
if (home == NULL)
return FAILED ("Where did my home go?");
if (tmp == NULL)
return FAILED ("Where did my /tmp go?");
return OK;
}
static Test path_tests [] = {
{"g_build_filename", test_buildfname},
{"g_buildpath", test_buildpath},
{"g_path_get_dirname", test_dirname},
{"g_path_get_basename", test_basename},
{"g_find_program_in_path", test_ppath},
{"g_find_program_in_path2", test_ppath2},
{"test_cwd", test_cwd },
{"test_misc", test_misc },
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(path_tests_init, path_tests)

Some files were not shown because too many files have changed in this diff Show More