summaryrefslogtreecommitdiffstats
path: root/avahi-common/alternative-test.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-08-21 20:53:24 +0000
committerLennart Poettering <lennart@poettering.net>2006-08-21 20:53:24 +0000
commit8cf0e9e31837c813fb05b90acfcec828e6309d76 (patch)
tree5a8920b54eab495d1a11c7b1bfba08e5211ae34c /avahi-common/alternative-test.c
parent2376babecb8f095a2bcbea3c3cbb3b1109291869 (diff)
follow Bonjour's hostname number incrementing algorithm for handling conflicts. On collision the name "foobar" will now become "foobar-2" and not "foobar2". (closes #40)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1250 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/alternative-test.c')
-rw-r--r--avahi-common/alternative-test.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/avahi-common/alternative-test.c b/avahi-common/alternative-test.c
index 010478c..b3ee4e9 100644
--- a/avahi-common/alternative-test.c
+++ b/avahi-common/alternative-test.c
@@ -29,19 +29,54 @@
#include "malloc.h"
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ const char* const test_strings[] = {
+ "gurke",
+ "",
+ "-",
+ " #",
+ "1",
+ "#0",
+ " #0",
+ " #1",
+ "#-1",
+ " #-1",
+ "-0",
+ "--0",
+ "-1",
+ "--1",
+ "-2",
+ "gurke1",
+ "gurke0",
+ "gurke-2",
+ "gurke #0",
+ "gurke #1",
+ "gurke #",
+ "gurke#1",
+ "gurke-",
+ "gurke---",
+ "gurke #",
+ "gurke ###",
+ NULL
+ };
+
char *r = NULL;
- int i, k;
+ int i, j, k;
+
+ for (k = 0; test_strings[k]; k++) {
- for (k = 0; k < 2; k++) {
+ printf(">>>>>%s<<<<\n", test_strings[k]);
+
+ for (j = 0; j < 2; j++) {
- for (i = 0; i < 20; i++) {
- char *n;
-
- n = i == 0 ? avahi_strdup("gurke") : (k ? avahi_alternative_service_name(r) : avahi_alternative_host_name(r));
- avahi_free(r);
- r = n;
-
- printf("%s\n", r);
+ for (i = 0; i < 20; i++) {
+ char *n;
+
+ n = i == 0 ? avahi_strdup(test_strings[k]) : (j ? avahi_alternative_service_name(r) : avahi_alternative_host_name(r));
+ avahi_free(r);
+ r = n;
+
+ printf("%s\n", r);
+ }
}
}