Add metrics library tests. Some metrics daemon API cleanup.
Refactor the metrics daemon API a little so that we don't need
to link in libmetrics into the daemon test binary.
Review URL: http://codereview.chromium.org/2079007
diff --git a/metrics/metrics_library.h b/metrics/metrics_library.h
index 2a6412c..8ae3f5b 100644
--- a/metrics/metrics_library.h
+++ b/metrics/metrics_library.h
@@ -5,9 +5,10 @@
#ifndef METRICS_LIBRARY_H_
#define METRICS_LIBRARY_H_
+#include <sys/types.h>
#include <string>
-// TODO(sosa@chromium.org): Add testing for send methods
+#include <gtest/gtest_prod.h> // for FRIEND_TEST
class MetricsLibraryInterface {
public:
@@ -21,6 +22,8 @@
// Library used to send metrics to both Autotest and Chrome/UMA.
class MetricsLibrary : public MetricsLibraryInterface {
public:
+ MetricsLibrary();
+
// Initializes the library.
void Init();
@@ -51,6 +54,30 @@
// Sends to Autotest and returns true on success.
static bool SendToAutotest(const std::string& name, int value);
+
+ private:
+ friend class MetricsLibraryTest;
+ FRIEND_TEST(MetricsLibraryTest, FormatChromeMessage);
+ FRIEND_TEST(MetricsLibraryTest, FormatChromeMessageTooLong);
+ FRIEND_TEST(MetricsLibraryTest, SendMessageToChrome);
+ FRIEND_TEST(MetricsLibraryTest, SendMessageToChromeUMAEventsBadFileLocation);
+
+ // Sends message of size |length| to Chrome for transport to UMA and
+ // returns true on success.
+ bool SendMessageToChrome(int32_t length, const char* message);
+
+ // Formats a name/value message for Chrome in |buffer| and returns the
+ // length of the message or a negative value on error.
+ //
+ // Message format is: | LENGTH(binary) | NAME | \0 | VALUE | \0 |
+ //
+ // The arbitrary |format| argument covers the non-LENGTH portion of the
+ // message. The caller is responsible to store the \0 character
+ // between NAME and VALUE (e.g. "%s%c%d", name, '\0', value).
+ int32_t FormatChromeMessage(int32_t buffer_size, char* buffer,
+ const char *format, ...);
+
+ const char* uma_events_file_;
};
#endif /* METRICS_LIBRARY_H_ */