1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #include "text_test_interpreter.h" 19 20 21 _STRING _yak_itoa(int input) 22 { 23 char buffer[32]; 24 sprintf(buffer, "%d", input); 25 return buffer; 26 } 27 28 //the header for the report 29 _STRING 30 text_test_interpreter::header(const test_result& result) const 31 { 32 _STRING Result("\nTest output begins\nNumber of tests: "); 33 _APPEND(Result, _yak_itoa(result.total_test_count())); 34 _APPEND(Result, "\n"); 35 return Result; 36 37 } 38 39 _STRING 40 text_test_interpreter::footer(const test_result& result) const 41 { 42 result.total_test_count(); 43 _STRING Result("Test output ends\n"); 44 return Result; 45 } 46 47 _STRING 48 text_test_interpreter::successes(const test_result& result) const 49 { 50 _STRING Result("Successes: "); 51 _APPEND(Result, _yak_itoa(result.success_count())); 52 _APPEND(Result, "\n"); 53 return Result; 54 } 55 56 _STRING 57 text_test_interpreter::failures(const test_result& result) const 58 { 59 _STRING Result("Failures: "); 60 _APPEND(Result, _yak_itoa(result.failures().size())); 61 _APPEND(Result, "\n"); 62 _APPEND(Result, problem_vector_string(result.failures())); 63 _APPEND(Result, "\n"); 64 return Result; 65 } 66 67 _STRING 68 text_test_interpreter::errors(const test_result& result) const 69 { 70 _STRING Result("Errors: "); 71 _APPEND(Result, _yak_itoa(result.errors().size())); 72 _APPEND(Result, "\n"); 73 _APPEND(Result, problem_vector_string(result.errors())); 74 _APPEND(Result, "\n"); 75 return Result; 76 } 77 78 _STRING 79 text_test_interpreter::problem_vector_string(const _VECTOR(test_problem, unit_test_allocator)& 80 vect) const 81 { 82 _STRING Result; 83 84 for (_VECTOR(test_problem, unit_test_allocator)::const_iterator iter = vect.begin(); 85 iter != vect.end(); 86 ++iter) 87 { 88 _APPEND(Result, problem_string(*iter)); 89 } 90 return Result; 91 } 92 93 _STRING 94 text_test_interpreter::problem_string(const test_problem& problem) const 95 { 96 _STRING Result; 97 _APPEND(Result, problem.filename()); 98 _APPEND(Result, ":"); 99 _APPEND(Result, _yak_itoa(problem.line_number())); 100 _APPEND(Result, ":"); 101 _APPEND(Result, problem.message()); 102 _APPEND(Result, "\n"); 103 return Result; 104 } 105 106 _STRING 107 text_test_interpreter::interpretation(const test_result& result_to_interpret) const 108 { 109 _STRING Result; 110 _APPEND(Result, header(result_to_interpret)); 111 _APPEND(Result, successes(result_to_interpret)); 112 _APPEND(Result, failures(result_to_interpret)); 113 _APPEND(Result, errors(result_to_interpret)); 114 _APPEND(Result, footer(result_to_interpret)); 115 return Result; 116 } 117 118