Very interesting question.
For a computer to understand whether song is happy or sad, you must define "happy" and "sad" first. This alone seems almost impossible, since every human has his own understanding of happiness, sadness and all other emotions.
You can define "sad songs" as the "songs which induce a sad mood in the listener". In this case, how can you know what effect the song will make on every individual human? For example, you can write a very happy song with major tonality and lyrics about summer and children, and an old man will cry while listening to it, because he remembered that his son died last summer.
As for the theory: many people think that major = happy and minor = sad. This is, generally, because of the relation to major and minor chords, which have a very different mood to them. Major thirds, which are the basis for major chords, sound happy and bright; and minor thirds, which are the basis for minor chords, sound dark and sad. This is the impression people usually get when they listen to the interval or chord alone. When chords line up to make up a song, the mood of the song is produced not from individual chords, but by tension and release made by chord sequences.
You cannot tell that a song with minor tonality will be accepted as "sad" or in major as "happy", because tonality does not matter; A minor and C major have all the same notes. It is tension/release and the listener's interpretation.
I don't think that computers will be able to understand music in any imaginable future.