htcache test, new
This commit is contained in:
		
							
								
								
									
										130
									
								
								smmapdfw/libsmmapdfw/htcachetest.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								smmapdfw/libsmmapdfw/htcachetest.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,130 @@ | ||||
| /* | ||||
|     Copyright (C) 2004,2005 Wolfgang Hottgenroth | ||||
|  | ||||
|     This file is part of smmapdfw. | ||||
|  | ||||
|     smmapdfw is free software; you can redistribute it and/or modify it | ||||
|     under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation; either version 2 of the License, or | ||||
|     (at your option) any later version.   | ||||
|  | ||||
|     smmapdfw is distributed in the hope that it will be useful, but WITHOUT | ||||
|     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||
|     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public | ||||
|     License for more details.  | ||||
|  | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with smmapdfw. If not, write to the Free Software Foundation, 59 | ||||
|     Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
| */ | ||||
|  | ||||
| #if HAVE_CONFIG_H | ||||
| # include "config.h" | ||||
| #endif | ||||
|  | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include <unistd.h> | ||||
| #include <syslog.h> | ||||
|  | ||||
| #include "htcache.h" | ||||
|  | ||||
|  | ||||
|    | ||||
|  | ||||
| int main(int argc, char **args) { | ||||
|   char* output; | ||||
|   int size; | ||||
|   int res; | ||||
|  | ||||
|   openlog("htcachetest", LOG_PID, LOG_LOCAL2); | ||||
|  | ||||
|   htcache_t *c = htcache_init("/tmp/test-cache", 10); | ||||
|  | ||||
|   printf("Populating cache\n"); | ||||
|   htcache_insert(c, "key1", "value1", 7); | ||||
|   htcache_insert(c, "key2", "value2", 7); | ||||
|   htcache_insert(c, "key3", "value3", 7); | ||||
|   htcache_insert(c, "key4", "value4", 7); | ||||
|   htcache_insert(c, "key5", "value5", 7); | ||||
|   htcache_insert(c, "key6", "value6", 7); | ||||
|   htcache_insert(c, "key7", "value7", 7); | ||||
|   htcache_insert(c, "key8", "value8", 7); | ||||
|   htcache_insert(c, "key9", "value9", 7); | ||||
|  | ||||
|   res = htcache_lookup(c, "key", &output, &size); | ||||
|   if (-1 != res) { | ||||
|     printf("Failure when nothing should be found\n"); | ||||
|   } else { | ||||
|     printf("Ok, not found when looking up not existing key\n"); | ||||
|   } | ||||
|  | ||||
|   res = htcache_lookup(c, "key5", &output, &size); | ||||
|   if (0 != res) { | ||||
|     printf("Failure when key5 should be found: %d\n", res); | ||||
|   } else { | ||||
|     printf("Ok, key5 found\n"); | ||||
|     if (size != 7) { | ||||
|       printf("  Failure: invalid size: %d\n", size); | ||||
|     } else if (strcmp(output, "value5")) { | ||||
|       printf("  Failure: invalid data: %s\n", output); | ||||
|     } | ||||
|     free(output); | ||||
|   } | ||||
|  | ||||
|   res = htcache_lookup(c, "key2", &output, &size); | ||||
|   if (0 != res) { | ||||
|     printf("Failure when key2 should be found: %d\n", res); | ||||
|   } else { | ||||
|     printf("Ok, key2 found\n"); | ||||
|     if (size != 7) { | ||||
|       printf("  Failure: invalid size: %d\n", size); | ||||
|     } else if (strcmp(output, "value2")) { | ||||
|       printf("  Failure: invalid data: %s\n", output); | ||||
|     } | ||||
|     free(output); | ||||
|   } | ||||
|  | ||||
|   printf("Add entry to cache\n"); | ||||
|   htcache_insert(c, "key_9", "value_9", 8); | ||||
|  | ||||
|   res = htcache_lookup(c, "key_9", &output, &size); | ||||
|   if (0 != res) { | ||||
|     printf("Failure when key_9 should be found: %d\n", res); | ||||
|   } else { | ||||
|     printf("Ok, key_9 found\n"); | ||||
|     if (size != 8) { | ||||
|       printf("  Failure: invalid size: %d\n", size); | ||||
|     } else if (strcmp(output, "value_9")) { | ||||
|       printf("  Failure: invalid data: %s\n", output); | ||||
|     } | ||||
|     free(output); | ||||
|   } | ||||
|  | ||||
|   printf("Sleeping a while\n"); | ||||
|   sleep(15); | ||||
|  | ||||
|  | ||||
|   res = htcache_lookup(c, "key2", &output, &size); | ||||
|   if (-2 != res) { | ||||
|     printf("Failure when nothing should be found with expiry code\n"); | ||||
|   } else { | ||||
|     printf("Ok, not found when looking up expired entry, got expiry code\n"); | ||||
|   } | ||||
|  | ||||
|   res = htcache_lookup(c, "key2", &output, &size); | ||||
|   if (-1 != res) { | ||||
|     printf("Failure when nothing should be found\n"); | ||||
|   } else { | ||||
|     printf("Ok, not found when looking up already expired entry\n"); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   htcache_destroy(c); | ||||
| } | ||||
|  | ||||
|  | ||||
|    | ||||
|    | ||||
|    | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 whottgen
					whottgen