int test_copy_sstring(void) { SString temp; if(copy_sstring(NULL, NULL) != NULL_ARGUMENT_SS) return -1; if(copy_sstring(&temp, NULL) != NULL_ARGUMENT_SS) return -2; if(test_copy_sstring_helper("") == true) return -3; if(test_copy_sstring_helper("test") == true) return -4; temp = new_sstring(NULL, 100, NULL); const char * inputStr = "some short string"; SString input = new_sstring(inputStr, 0, NULL); if(copy_sstring(&temp, &input) == NULL_ARGUMENT_SS || strcmp(temp.string, inputStr) != 0 || temp.size != 100 || temp.length != strlen(inputStr)) return -5; free_sstring(&temp); free_sstring(&input); return 0; }
/* * Decrement reference count for a program. If it is 0, then free the prgram. * The flag free_sub_strings tells if the propgram plus all used strings * should be freed. They normally are, except when objects are swapped, * as we want to be able to read the program in again from the swap area. * That means that strings are not swapped. */ void free_prog(struct program *progp) { extern int total_program_size; int i; if (d_flag & DEBUG_PROG_REF) (void)printf("free_prog: %s\n", progp->name); if (!progp->ref || --progp->ref > 0) return; if (progp->ref < 0) fatal("Negative ref count for prog ref.\n"); if (progp == prog_list) prog_list = progp->next_all; progp->prev_all->next_all = progp->next_all; progp->next_all->prev_all = progp->prev_all; if (progp->next_all == progp) prog_list = 0; total_program_size -= progp->exec_size; total_prog_block_size -= progp->total_size; total_num_prog_blocks--; /* Free all function names. */ for (i=0; i < (int)progp->num_functions; i++) if (progp->functions[i].name) free_sstring(progp->functions[i].name); /* Free all variable names */ for (i=0; i < (int)progp->num_variables; i++) free_sstring(progp->variable_names[i].name); /* Free all inherited objects */ for (i=0; i < (int)progp->num_inherited - 1; i++) { free_prog(progp->inherit[i].prog); free_sstring(progp->inherit[i].name); } free_sstring(progp->inherit[i].name); free(progp->name); free((char *)progp->program); if (progp->line_numbers != 0) free((char *)progp->line_numbers); free((char *)progp); }
bool test_copy_sstring_helper(const char * string) { SString output = (SString){0}; SString input = new_sstring(string, 0, NULL); if(copy_sstring(&output, &input) == NULL_ARGUMENT_SS) return true; if(strcmp(output.string, string) != 0) return true; free_sstring(&output); free_sstring(&input); return false; }
int test_sstring_allocation(void) { SString test = (SString){0}; test = new_sstring(NULL, 0, NULL); if(test.size != 0 || test.length != 0 || test.string != NULL) return -1; char * temp = "something"; test = new_sstring(temp, 0, NULL); if(test.size != strlen(temp) + 1 || test.length != strlen(temp) || test.string == NULL || strcmp(test.string, temp) != 0) return -2; free_sstring(&test); if(test.size != 0 || test.length != 0 || test.string != NULL) return -3; test = new_sstring(NULL, 2, NULL); if(test.size != 2 || test.length != 0 || test.string == NULL || test.string[0] != '\0') return -4; free_sstring(&test); char * temp2 = "another longer test string"; test = new_sstring(temp2, 10, NULL); if(test.size != 10 || test.length != 9 || test.string == NULL || strncmp(test.string, temp2, 9) != 0) return -5; free_sstring(&test); return 0; }
bool test_to_upper_sstring_helper(const char * input, const char * output) { SString test = new_sstring(input, 0, NULL); SString upperstring = to_upper_sstring(&test, NULL); if(output != NULL) { if(strcmp(output, upperstring.string) != 0) return true; } else { if(upperstring.string != NULL) return true; } free_sstring(&test); free_sstring(&upperstring); return false; }
void remove_living_name(struct object *ob) { struct object **hl; num_living_names--; if (!ob->living_name) fatal("remove_living_name: no living name set.\n"); hl = &hashed_living[LivHash(ob->living_name)]; while(*hl) { if (*hl == ob) break; hl = &(*hl)->next_hashed_living; } if (*hl == 0) fatal("remove_living_name: Object named %s no in hash list.\n", ob->living_name); *hl = ob->next_hashed_living; free_sstring(ob->living_name); ob->next_hashed_living = 0; ob->living_name = 0; }