From: Thiago Farina <tfransosi@gmail.com>
To: git@vger.kernel.org
Cc: gister@pobox.com, Thiago Farina <tfransosi@gmail.com>
Subject: [PATCH] Add test-string-list.c
Date: Sat, 4 Sep 2010 23:34:21 -0300 [thread overview]
Message-ID: <4f798daaf4631e00927b455b77919d5bb8fade03.1283653854.git.tfransosi@gmail.com> (raw)
Add a simple test that demonstrates how to create and manipulate
a list of strings using the string-list.h API.
To see the test, call it by:
./bin-wrappers/test-string-list.c
Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
Makefile | 1 +
test-string-list.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
create mode 100644 test-string-list.c
diff --git a/Makefile b/Makefile
index 40fbcae..287bc2c 100644
--- a/Makefile
+++ b/Makefile
@@ -422,6 +422,7 @@ TEST_PROGRAMS_NEED_X += test-string-pool
TEST_PROGRAMS_NEED_X += test-svn-fe
TEST_PROGRAMS_NEED_X += test-treap
TEST_PROGRAMS_NEED_X += test-index-version
+TEST_PROGRAMS_NEED_X += test-string-list
TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
diff --git a/test-string-list.c b/test-string-list.c
new file mode 100644
index 0000000..11b8a7f
--- /dev/null
+++ b/test-string-list.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <string.h>
+#include "string-list.h"
+
+int main(int argc, const char **argv)
+{
+ struct string_list list;
+ int i;
+
+ memset(&list, 0, sizeof(struct string_list));
+
+ string_list_append(&list, "foo");
+ string_list_append(&list, "bar");
+
+ for (i = 0; i < list.nr; i++)
+ printf("%s\n", list.items[i].string);
+
+ print_string_list(&list, "");
+
+ int has_foo = string_list_has_string(&list, "foo");
+ if (has_foo != 1)
+ error("List doesn't have foo.");
+
+ string_list_clear(&list, 0);
+ if (list.nr > 0)
+ error("List is not clear.");
+
+ return 0;
+}
--
1.7.2.3.313.gcd15
next reply other threads:[~2010-09-05 2:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-05 2:34 Thiago Farina [this message]
2010-09-05 5:02 ` [PATCH] Add test-string-list.c Jonathan Nieder
2010-09-06 6:12 ` Junio C Hamano
2010-09-06 23:48 ` Thiago Farina
2010-09-07 0:07 ` Jonathan Nieder
2010-09-07 12:04 ` Thiago Farina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f798daaf4631e00927b455b77919d5bb8fade03.1283653854.git.tfransosi@gmail.com \
--to=tfransosi@gmail.com \
--cc=gister@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).